#Adding generic Type struct into Enum without having to introduce a generic Type parameter
10 messages · Page 1 of 1 (latest)
a Value<String> holds an Object<String> in the Obj variant, and Value<Foo> holds an Object<Foo> in the Obj variant
The thing is implementing it with a generic type parameter absolutely destroys my VM. My VM has a stack that holds a Vec<Value> introducing a generic would mean i have Vec<Value<T>> which would limit me in the things i can push to the stack
if you want to use the same Value type, regardless of the inner object type, then make it a trait object, not a generic
Box<dyn SomeTrait>
Yes but I dont quite see how I can dodge the generic type parameter by introducing a trait. Like How can I encode the information of my ObjectString into a trait?
you use a trait object instead of the generic parameter
struct Foo<T: SomeTrait>(T) vs struct Foo(Box<dyn SomeTrait>)
Hey, thank you! I'll try to implement it!