Created
October 6, 2018 11:03
-
-
Save ryochack/29d02cbad5ba055efa5a1af37b860fb7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io; | |
#[derive(Debug)] | |
/// tuple-like struct | |
struct Foo(i32); | |
fn num(n: i32) -> io::Result<i32> { | |
Ok(n) | |
} | |
/// tuple-like struct `Foo` implements `FnOnce(i32) -> Self` | |
fn f<F: FnOnce(i32) -> Foo> (g: F, n: i32) -> Foo { | |
g(n) | |
} | |
fn main() { | |
println!("{:?}", num(10).map(Foo)); | |
// => Ok(Foo(10)) | |
println!("{:?}", f(Foo, 20)); | |
// => Foo(20) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment