Downcasting a type with a named lifetime parameter
I have the following code: use std::any::Any; use std::borrow::Cow; // Base trait for downcasting pub trait AsTranslationUnit<'a> { fn as_any(&self) -> &dyn Any; } pub trait TranslationUnit<'a>: AsTranslationUnit<'a> { fn file_stem(&self) -> &Cow<'a, str>; } // Implementation of AsTranslationUnit for all types implementing TranslationUnit impl<'a, T: TranslationUnit<'a> + 'a> AsTranslationUnit<'a> for T { fn as_any(&self) -> &dyn Any { self } } #[derive(Debug, PartialEq, Eq, Clone, Default)] pub struct ModuleInterfaceModel<'a> { pub file_stem: Cow<'a, str>, } impl<'a> TranslationUnit<'a> for M
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.