Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(nll)]
- fn main() {
- println!("Hello, world!");
- let mut test = String::from("12345");
- let mut obj1 = Object {
- text : test.as_mut_str()
- ,next : None
- };
- for i in 0..5 {
- obj1 = *obj1.split_text(4 - i);
- if let Some(obj) = obj1.next.as_ref() {
- println!("{}", obj.text);
- }
- }
- }
- struct Object<'a> {
- text : &'a mut str
- ,next : Option<Box<Object<'a>>>
- }
- impl <'a> Object<'a> {
- fn split_text(&'a mut self, count:usize) -> &'a mut Self {
- let tmp = &mut self.text;
- let (part1, part2) = tmp.split_at_mut(count);
- self.text = part1;
- let obj2 = Object {
- text : part2
- ,next : None
- };
- self.next = Some(Box::new(obj2));
- self
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement