diff options
Diffstat (limited to 'rust/graph/graph2.rs')
-rw-r--r-- | rust/graph/graph2.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/rust/graph/graph2.rs b/rust/graph/graph2.rs new file mode 100644 index 0000000..1e57f19 --- /dev/null +++ b/rust/graph/graph2.rs @@ -0,0 +1,17 @@ +#[derive(Debug)] +struct Node<'a> { + label: i32, + next: Option<&'a Node<'a>>, +} + + +fn main () { + let mut n = Node { label: 1, next: None }; + unsafe { + let raw = &mut n as *mut Node; + (*raw).next = Some(&n); + } + println!("{}", n.label); + println!("{}", n.next.unwrap().label); + println!("{}", n.next.unwrap().next.unwrap().label); +} |