Guest User

Untitled

a guest
Jan 18th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. fn main() {
  2. let words = "Sometimes think, the greatest sorrow than older";
  3. let foo = Foo::new(words);
  4. let first = foo.split_first_a();
  5. println!("{}", first);
  6.  
  7. let first = Foo::new(words).split_first_b();
  8. println!("{}", first);
  9.  
  10. println!("{}", Foo::new(words).split_first_a());
  11. }
  12.  
  13. struct Foo<'a> {
  14. part: &'a str,
  15. }
  16.  
  17. impl<'a> Foo<'a> {
  18. fn split_first_a(&'a self) -> &'a str {
  19. self.part.split(',').next().expect("Could not find a ','")
  20. }
  21.  
  22. fn split_first_b(&self) -> &'a str {
  23. self.part.split(',').next().expect("Could not find a ','")
  24. }
  25.  
  26. fn new(s: &'a str) -> Self {
  27. Foo { part: s }
  28. }
  29. }
Add Comment
Please, Sign In to add comment