Created
April 5, 2016 01:40
-
-
Save kscz/3942f6d5e96b58e32a0d5049ef75d731 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
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