Skip to content

Instantly share code, notes, and snippets.

@dobkeratops
Last active July 30, 2017 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dobkeratops/18d4e1e8d0111ce47a9d15e41ee86c75 to your computer and use it in GitHub Desktop.
Save dobkeratops/18d4e1e8d0111ce47a9d15e41ee86c75 to your computer and use it in GitHub Desktop.
// is there a way to bound the 'TRAIT_OBJECT' type param to tell it *this is a trait object*?
// context..
// looking for ways of streamlining code dealing with boxed-trait-objects
impl Editor{
pub fn set_tool<'e,E:MTool<EdScene>+Clone>(&'e mut self,data:E) where E:'static{
self.mtool = new_object(data);
//Box::new(data) as Box<MTool<EdScene>> // <<<<<<< WAS THIS...
}
}
// Want: helper function to
// box a struct and bind with a vtable, infering types from context.
//
fn new_object<S:Clone,TRAIT_OBJECT>(data:S)->TRAIT_OBJECT{
Box::new(data.clone()) as TRAIT_OBJECT // <<<< ERROR NON SCALAR CAST
}
// I've tried a macro, but macros confuse IntellijIDE.
// relying on macros= harder for tools to navigate.
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment