Advertisement
Guest User

Untitled

a guest
Sep 19th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.53 KB | None | 0 0
  1. fn main() {
  2.     let novel = String::from("Call me Ishmael. Some years ago...");
  3.     let first_sentence = novel.split('.')
  4.         .next()
  5.         .expect("Could not find a '.'");
  6.     let i = ImportantExcerpt { part: first_sentence };
  7.     i.announce_and_return_part("hi");
  8. }
  9.  
  10. struct ImportantExcerpt<'a> {
  11.    part: &'a str,
  12. }
  13.  
  14. impl<'a> ImportantExcerpt<'a> {
  15.     fn announce_and_return_part<'b, 'c>(&'b self, announcement: &'c str) -> &'a str {
  16.        println!("Attention please: {}", announcement);
  17.        self.part
  18.    }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement