Guest User

Untitled

a guest
Nov 18th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. use std::mem;
  2.  
  3. #[derive(Debug)]
  4. struct CharList {
  5. c: char,
  6. next: Option<Box<CharList>>,
  7. }
  8.  
  9. fn make(s:&str) -> CharList {
  10. let mut result = CharList{
  11. c: 'a',
  12. next: None
  13. };
  14. {
  15. let mut tail = &mut result.next;
  16. for c in s.chars() {
  17. let cl = CharList {
  18. c: c,
  19. next: None
  20. };
  21. mem::replace(tail, Some(Box::new(cl)));
  22. let next = &mut tail.as_mut().unwrap().next;
  23. tail = next
  24. }
  25. }
  26. result
  27. }
  28.  
  29. fn main() {
  30. println!("Value: {:?}", make("bcdef"));
  31. }
Add Comment
Please, Sign In to add comment