<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          mrustymruby 對(duì) Rust 的安全約束

          聯(lián)合創(chuàng)作 · 2023-09-30 21:46

          mrusty 可以讓你在 mruby 中使用 Rust 的結(jié)構(gòu)和枚舉并運(yùn)行它們。

          示例代碼:

          // 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".
          瀏覽 22
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  日韩A片视频免费看 | 蜜桃AV天堂| 五月天黄色小说 | 日本一道本视频一二三 | 一本色道久久综合无码欧美 |