Skip to content

Instantly share code, notes, and snippets.

@octave99
Created June 27, 2019 17:02
Show Gist options
  • Save octave99/f53eb418289d746b696e06252364c08b to your computer and use it in GitHub Desktop.
Save octave99/f53eb418289d746b696e06252364c08b to your computer and use it in GitHub Desktop.
use std::{
borrow::{Borrow, Cow},
fmt::Debug,
};
fn say<'a, C, B>(first_name: C, last_name: &B)
where
C: Into<Cow<'a, str>> + Debug + ?Sized,
B: Borrow<str> + Debug + ?Sized,
{
print!("{:?} {:?}", first_name, last_name.borrow());
}
fn main() {
say("John", "Smith");
let first_name = "John";
let last_name = "Smith";
// let last_name = "Smith".to_owned(); // expected reference, found struct `std::string::String` help: consider borrowing here: `&last_name`
say(first_name, last_name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment