I'm thinking there may be some benefit to adding some generic fields to the Instance struct. Something like
#[derive(PartialEq, Clone)]
pub struct Instance {
pub class: Managed<Class>,
fields: Box<[Value]>,
native_data: Option<Managed<ManagedAny>>
}
I think this gives us some options to store extra data related to native functionality without need several new types to values. The example in mind is the beginnings of the regexp module. Here I'm primarily just wrapping the regex crate. For each of the three test methods I have test, match and captures I have currently construct a new Regex struct each time this is invoked which is quite wasteful. Instead I could make a new trait ManagedAny something like
trait ManagedAny : Manage + any::Any {}
This way I can store essentially arbitrary extra data on an instance such as a Regex struct and implement the normal Manage members. Inside methods on my Regexp class I should be able to call.
let instance = this.unwrap().to_instance();
let regex = match instance.native_data.downcast_ref::<Regex>().expect("Expected Regex")
// use regex
I'm thinking there may be some benefit to adding some generic fields to the
Instancestruct. Something likeI think this gives us some options to store extra data related to native functionality without need several new types to values. The example in mind is the beginnings of the
regexpmodule. Here I'm primarily just wrapping theregexcrate. For each of the three test methods I havetest,matchandcapturesI have currently construct a newRegexstruct each time this is invoked which is quite wasteful. Instead I could make a new traitManagedAnysomething likeThis way I can store essentially arbitrary extra data on an instance such as a
Regexstruct and implement the normalManagemembers. Inside methods on myRegexpclass I should be able to call.