Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- let words = "Sometimes think, the greatest sorrow than older";
- let foo = Foo::new(words);
- let first = foo.split_first_a();
- println!("{}", first);
- let first = Foo::new(words).split_first_b();
- println!("{}", first);
- println!("{}", Foo::new(words).split_first_a());
- }
- struct Foo<'a> {
- part: &'a str,
- }
- impl<'b, 'a: 'b> Foo<'a> {
- fn split_first_a(&'a self) -> &'a str {
- self.part.split(',').next().expect("Could not find a ','")
- }
- fn split_first_b(&'b self) -> &'a str {
- self.part.split(',').next().expect("Could not find a ','")
- }
- fn new(s: &'a str) -> Self {
- Foo { part: s }
- }
- }
Add Comment
Please, Sign In to add comment