File: typed_data.rs

package info (click to toggle)
rust-magnus 0.8.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,756 kB
  • sloc: ruby: 150; sh: 17; makefile: 2
file content (28 lines) | stat: -rw-r--r-- 648 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#![cfg(feature = "embed")]

use magnus::{embed::init, eval, rb_assert, Ruby, Value};

#[magnus::wrap(class = "Example", free_immediately)]
struct Example {
    value: String,
}

fn make_rb_example(ruby: &Ruby, value: &str) -> Value {
    let ex = Example {
        value: value.to_owned(),
    };
    ruby.into_value(ex)
}

#[test]
fn it_wraps_rust_struct() {
    let ruby = unsafe { init() };

    ruby.define_class("Example", ruby.class_object()).unwrap();

    let val = make_rb_example(&ruby, "foo");
    rb_assert!(ruby, "val.class == Example", val);

    let ex: &Example = eval!(ruby, "val", val).unwrap();
    assert_eq!("foo", ex.value)
}