Last active
July 30, 2017 07:41
-
-
Save dobkeratops/18d4e1e8d0111ce47a9d15e41ee86c75 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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