summaryrefslogtreecommitdiff
path: root/rust
diff options
context:
space:
mode:
authorKjetil Orbekk <kjetil.orbekk@gmail.com>2016-06-10 00:30:58 -0400
committerKjetil Orbekk <kjetil.orbekk@gmail.com>2016-06-10 00:30:58 -0400
commit7374f65411d76dfe855d345f87dddb2fcda7ce5e (patch)
tree022d4c72da2fc0591e32e28bd28cb3b60508dc12 /rust
parent2af185e93765fd0b8e6bf5f3c15931413f8e86ca (diff)
Unsafe pointer example.
Diffstat (limited to 'rust')
-rw-r--r--rust/graph/Cargo.toml4
-rw-r--r--rust/graph/graph2.rs17
2 files changed, 21 insertions, 0 deletions
diff --git a/rust/graph/Cargo.toml b/rust/graph/Cargo.toml
index adabedc..eb0841b 100644
--- a/rust/graph/Cargo.toml
+++ b/rust/graph/Cargo.toml
@@ -9,3 +9,7 @@ itertools = "0.4.15"
[[bin]]
name = "graph"
path = "graph.rs"
+
+[[bin]]
+name = "graph2"
+path = "graph2.rs"
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);
+}