Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #![feature(nll)]
  2.  
  3. fn main() {
  4. println!("Hello, world!");
  5. let mut test = String::from("12345");
  6. let mut obj1 = Object {
  7. text : test.as_mut_str()
  8. ,next : None
  9. };
  10. for i in 0..5 {
  11. obj1 = *obj1.split_text(4 - i);
  12. if let Some(obj) = obj1.next.as_ref() {
  13. println!("{}", obj.text);
  14. }
  15. }
  16. }
  17.  
  18. struct Object<'a> {
  19. text : &'a mut str
  20. ,next : Option<Box<Object<'a>>>
  21. }
  22.  
  23. impl <'a> Object<'a> {
  24. fn split_text(&'a mut self, count:usize) -> &'a mut Self {
  25. let tmp = &mut self.text;
  26. let (part1, part2) = tmp.split_at_mut(count);
  27. self.text = part1;
  28. let obj2 = Object {
  29. text : part2
  30. ,next : None
  31. };
  32. self.next = Some(Box::new(obj2));
  33. self
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement