danielpclark / rutie

“The Tie Between Ruby and Rust.”
MIT License
939 stars 62 forks source link

What should I do if I want to keep a reference in Rust side? #189

Closed yfractal closed 3 weeks ago

yfractal commented 3 weeks ago

For example:

    fn ruby_insert(key: RString, obj: AnyObject) -> AnyObject {
        let struct = rtself.get_data_mut(&*STORE_WRAPPER);

        let ruby_obj = RubyObject::from(obj.unwrap().value());

        struct
            .hash_map
            .insert(key.unwrap().to_string(), Arc::new(ruby_obj));
        NilClass::new().into()
    },

I think I have to pin the object first to avoid the memory being moved and then keep a reference in rtself to avoid the memory has been freed.

Are there any other things I need to do?