mruby对Rust的安全约束 mrusty

码农软件 · 软件分类 · 其他开发相关 · 2019-10-18 18:11:25

软件介绍

mrusty 可以让你在 mruby 中使用 Rust 的结构和枚举并运行它们。

示例代码:

// mrfn!
#[macro_use]
extern crate mrusty;

// Needs some undocumented, hidden calls.
use mrusty::*;

let mruby = MRuby::new();

struct Cont {
    value: i32
}

// Cont should not flood the current namespace. We will add it with require.
impl MRubyFile for Cont {
    fn require(mruby: MRubyType) {
        mruby.def_class::<Cont>("Container");

        // Converts mruby types automatically & safely.
        // slf is always Value in initialize().
        mruby.def_method::<Cont, _>("initialize", mrfn!(|_mruby, slf: Value, v: i32| {
            let cont = Cont { value: v };

            slf.init(cont)
        }));
        mruby.def_method::<Cont, _>("value", mrfn!(|mruby, slf: Cont| {
            mruby.fixnum(slf.value)
        }));
    }
}

// Add file to the context, making it requirable.
mruby.def_file::<Cont>("cont");

// Add spec testing.
describe!(Cont, "
  context 'when containing 1' do
    it 'returns 1 when calling #value' do
      expect(Container.new(1).value).to eql 1
    end
  end
");

let result = mruby.run("
    require 'cont'

    Container.new(3).value
").unwrap(); // Returns Value.

println!("{}", result.to_i32().unwrap()); // Prints "3".

本文地址:https://codercto.com/soft/d/17045.html

算法设计与分析

算法设计与分析

郑宗汉/郑晓明编 / 清华大学出版社 / 2005-6 / 32.00元

《算法设计与分析》系统地介绍算法设计与分析的概念和方法,共四部分内容,第一部分包括前两章,介绍算法设计与分析的基本概念及必要的数学工具,对算法的时间复杂性的概念及算法的分析方法作了较为详细的叙述。第二部分包括第3~~9章,以算法设计技术为纲,从排序问题和离散集合的操作开始,进而介绍递归技术、分治法、贪婪法、动态规划、回溯法、分支与限界法以及随机算法等算法设计技术及其复杂性。第三部分包括第10章和第......一起来看看 《算法设计与分析》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

在线进制转换器
在线进制转换器

各进制数互转换器

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具