Skip to content

Instantly share code, notes, and snippets.

@rustyrazorblade
Created March 16, 2015 20:11
Show Gist options
  • Save rustyrazorblade/4b3c50a7dd89a984d032 to your computer and use it in GitHub Desktop.
Save rustyrazorblade/4b3c50a7dd89a984d032 to your computer and use it in GitHub Desktop.
unsafe rust most basic example ever
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