Guest User

Untitled

a guest
Sep 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. trait GetPossibleRef<'a> {
  2. type Result;
  3. fn get_data(&'a self) -> Self::Result;
  4. }
  5.  
  6. struct Base(f32);
  7.  
  8. impl<'a> GetPossibleRef<'a> for Base {
  9. type Result = &'a f32;
  10. fn get_data(&'a self) -> Self::Result {
  11. &self.0
  12. }
  13. }
  14.  
  15. fn main() {
  16. let x = Base(42.3);
  17. let b: Box<dyn GetPossibleRef<Result = &f32>> = Box::new(x);
  18.  
  19. println!("{:?}", b.get_data());
  20. }
Add Comment
Please, Sign In to add comment