Created
March 16, 2015 20:11
-
-
Save rustyrazorblade/4b3c50a7dd89a984d032 to your computer and use it in GitHub Desktop.
unsafe rust most basic example ever
This file contains 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 Vertex { | |
id: i32, | |
} | |
impl Vertex { | |
fn test(&mut self, num:i32) { | |
self.id = num; | |
} | |
} | |
fn main() { | |
let mut v = Vertex{id:1}; | |
unsafe { | |
let v2: *mut Vertex = &mut v; | |
v2.as_mut().unwrap().test(5); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment