Skip to content

Instantly share code, notes, and snippets.

@killercup
Created August 4, 2016 13:29
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 killercup/23b98645fa7fd68cb9e28da9425a62f9 to your computer and use it in GitHub Desktop.
Save killercup/23b98645fa7fd68cb9e28da9425a62f9 to your computer and use it in GitHub Desktop.
#![allow(unused_variables)]
// A bit more typing for the API author.
// (Sadly, the parameters need to be specified individually – or Rust would
// infer the concrete type from the first parameter given. This reads not as
// nicely, and documentation might not look as pretty as before.)
fn foo<I, D, S>(lorem: &str, ipsum: I, dolor: D, sit: S) where
I: Into<Option<i32>>,
D: Into<Option<i32>>,
S: Into<Option<i32>>,
{
println!("{}", lorem);
}
fn main() {
foo("bar", None, None, None); // Still weird
foo("bar", 42, None, None); // Okay
foo("bar", 42, 1337, -1); // Wow, that's nice! Gimme more APIs like this!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment