Guest User

Untitled

a guest
May 24th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. trait Foo {
  2. type Output;
  3.  
  4. fn foo<F: FnOnce() -> i32>(self, f: F) -> Self::Output;
  5. }
  6.  
  7. fn bar<F: FnOnce() -> i32>(_: F) -> &'static str {"blah"}
  8.  
  9. struct Bar;
  10.  
  11. impl Foo for Bar {
  12. type Output = &'static str;
  13.  
  14. fn foo<F: FnOnce() -> i32>(self, f: F) -> Self::Output {
  15. bar(f)
  16. }
  17. }
  18.  
  19. fn never_gonna_give_you_up<F: Foo>(f: F) -> F::Output {
  20. f.foo(|| 42)
  21. }
  22.  
  23. fn main() {
  24. println!("{}", never_gonna_give_you_up(Bar));
  25. }
Add Comment
Please, Sign In to add comment