mrusty mruby 对 Rust 的安全约束开源项目

我要开发同款
诺克萨斯2016年03月04日
97阅读

技术信息

开源地址
https://github.com/anima-engine/mrusty
授权协议
MPL-2.0

作品详情

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

示例代码:

// mrf!#[macro_use]exter crate mrusty;// Needs some udocumeted, hidde calls.use mrusty::*;let mruby = MRuby::ew();struct Cot {    value: i32}// Cot should ot flood the curret amespace. We will add it with require.impl MRubyFile for Cot {    f require(mruby: MRubyType) {        mruby.def_class::<Cot>("Cotaier");        // Coverts mruby types automatically & safely.        // slf is always Value i iitialize().        mruby.def_method::<Cot, _>("iitialize", mrf!(|_mruby, slf: Value, v: i32| {            let cot = Cot { value: v };            slf.iit(cot)        }));        mruby.def_method::<Cot, _>("value", mrf!(|mruby, slf: Cot| {            mruby.fixum(slf.value)        }));    }}// Add file to the cotext, makig it requirable.mruby.def_file::<Cot>("cot");// Add spec testig.describe!(Cot, "  cotext 'whe cotaiig 1' do    it 'returs 1 whe callig #value' do      expect(Cotaier.ew(1).value).to eql 1    ed  ed");let result = mruby.ru("    require 'cot'    Cotaier.ew(3).value").uwrap(); // Returs Value.pritl!("{}", result.to_i32().uwrap()); // Prits "3".

功能介绍

mrusty 可以让你在 mruby 中使用 Rust 的结构和枚举并运行它们。 示例代码:
// mrfn!
#[macro_use]
extern crate mrusty;

...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论