Skip to content

Instantly share code, notes, and snippets.

@kscz
Created April 5, 2016 01:40
Show Gist options
  • Save kscz/3942f6d5e96b58e32a0d5049ef75d731 to your computer and use it in GitHub Desktop.
Save kscz/3942f6d5e96b58e32a0d5049ef75d731 to your computer and use it in GitHub Desktop.
struct Neato {
burrito: String
}
impl Neato {
pub fn new(ingredients: &str) -> Neato {
Neato { burrito: String::from(ingredients) }
}
// I put explicit lifetimes here, but rust would have guessed this normally
pub fn print_and_unwrap_burrito<'a>(&'a self, print_me: &str) -> &'a str {
print!("{}", print_me);
&self.burrito
}
}
fn main() {
let x = Neato::new("cheese, beans, rice, and steak");
let y = x.print_and_unwrap_burrito("Neato burrito with ");
println!("{}", y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment