Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait Foo {
- type Output;
- fn foo<F: FnOnce() -> i32>(self, f: F) -> Self::Output;
- }
- fn bar<F: FnOnce() -> i32>(_: F) -> &'static str {"blah"}
- struct Bar;
- impl Foo for Bar {
- type Output = &'static str;
- fn foo<F: FnOnce() -> i32>(self, f: F) -> Self::Output {
- bar(f)
- }
- }
- fn never_gonna_give_you_up<F: Foo>(f: F) -> F::Output {
- f.foo(|| 42)
- }
- fn main() {
- println!("{}", never_gonna_give_you_up(Bar));
- }
Add Comment
Please, Sign In to add comment