Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. struct Foo(u32);
  2.  
  3. impl Foo {
  4. // Currently have to write this:
  5. fn bar(self) {
  6. let Foo(inner) = self;
  7. }
  8. // Would prefer to write (something like) this:
  9. fn baz(Self(inner)) {
  10. // However, as it currently is, this is an associated function - not a method.
  11. }
  12. }
  13.  
  14. fn main() {
  15. let x = Foo(4);
  16. x.bar();
  17. // Because baz is an associated method we cannot write:
  18. x.baz();
  19. }
  20.  
  21. // Is what's in 'bar' currently the best way of unwrapping wrapped values?
  22. // Or is there some alternative akin to 'baz'?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement