Skip to content

Instantly share code, notes, and snippets.

@ryochack
Created October 6, 2018 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryochack/29d02cbad5ba055efa5a1af37b860fb7 to your computer and use it in GitHub Desktop.
Save ryochack/29d02cbad5ba055efa5a1af37b860fb7 to your computer and use it in GitHub Desktop.
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