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

APP蓝图

APP蓝图

吕皓月 / 清华大学出版社 / 2015-1-1 / 69.00

移动互联网原型设计,简单来说,就是使用建模软件制作基于手机或者平板电脑的App,HTML 5网站的高保真原型。在7.0 之前的版本中,使用Axure RP进行移动互联网的建模也是可以的。比如,对于桌面的网站模型,制作一个1024像素宽度的页面就可以了;现在针对移动设备,制作320像素宽度的页面就好了。但是在新版本的Axure RP 7.0 中,加入了大量对于移动互联网的支持,如手指滑动,拖动,横屏......一起来看看 《APP蓝图》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具