Guest User

Untitled

a guest
Jun 24th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. struct A { field_a: i32 }
  2.  
  3. struct B<'a> { field_b: &'a A }
  4.  
  5. struct C<'b, 'a: 'b> { field_b: &'b B<'a> }
  6. struct MutC<'b, 'a: 'b> { field_b: &'b mut B<'a> }
  7.  
  8. trait Tr<'b, 'a> {
  9. fn field_b(&self) -> &'b B<'a>;
  10.  
  11. fn stuff(&self) {
  12. self.field_b(); // Imagine i do stuff with this here
  13. }
  14. }
  15.  
  16. impl<'b, 'a> Tr<'b, 'a> for C<'b, 'a> {
  17. fn field_b(&self) -> &'b B<'a>{
  18. self.field_b
  19. }
  20. }
  21.  
  22. impl<'b, 'a> Tr<'b, 'a> for MutC<'b, 'a> {
  23. fn field_b(&self) -> &'b B<'a>{
  24. self.field_b
  25. }
  26. }
  27.  
  28.  
  29. fn main() {
  30. println!("Hello, world!");
  31. }
Add Comment
Please, Sign In to add comment