Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. mod foo {
  2. pub struct Foo<T> {
  3. bar: usize,
  4. inner: T,
  5. }
  6.  
  7. impl<T> Foo<T> {
  8. pub fn new(inner: T) -> Self {
  9. Self { bar: 0, inner }
  10. }
  11. }
  12.  
  13. impl<T> core::ops::Deref for Foo<T> {
  14. type Target = T;
  15. fn deref(&self) -> &Self::Target {
  16. &self.inner
  17. }
  18. }
  19. }
  20.  
  21. struct Bar {
  22. bar: usize,
  23. }
  24.  
  25. fn main() {
  26. let foo = foo::Foo::new(Bar { bar: 1 });
  27. println!("{}", foo.bar);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement