Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::mem;
- #[derive(Debug)]
- struct CharList {
- c: char,
- next: Option<Box<CharList>>,
- }
- fn make(s:&str) -> CharList {
- let mut result = CharList{
- c: 'a',
- next: None
- };
- {
- let mut tail = &mut result.next;
- for c in s.chars() {
- let cl = CharList {
- c: c,
- next: None
- };
- mem::replace(tail, Some(Box::new(cl)));
- let next = &mut tail.as_mut().unwrap().next;
- tail = next
- }
- }
- result
- }
- fn main() {
- println!("Value: {:?}", make("bcdef"));
- }
Add Comment
Please, Sign In to add comment