Created
January 29, 2014 12:39
-
-
Save JohnMurray/8687063 to your computer and use it in GitHub Desktop.
Simple linked-list struct in Rust that doesn't work.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Node<T> { | |
value: T, | |
next: Option<~Node<T>> | |
} | |
struct LinkedList<T> { | |
head: ~Node<T>, | |
tail: ~Node<T> | |
} | |
impl<T> LinkedList<T> { | |
fn new(item: T) -> LinkedList<T> { | |
let node = ~Node { value: item, next: None }; | |
LinkedList { head: node, tail: node } | |
} | |
} | |
fn main() { | |
let n: LinkedList<~str> = LinkedList::new(~"hey there"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment