Guest User

Untitled

a guest
Feb 15th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. use std::ptr;
  2.  
  3. struct A {
  4. a: i32,
  5. b: *const i32
  6. }
  7.  
  8. impl A {
  9. pub fn new(a: i32) -> Self {
  10. let mut result = Self {
  11. a,
  12. b: ptr::null()
  13. };
  14. let ptr = &result.a as *const _;
  15. result.b = ptr;
  16.  
  17. unsafe {
  18. println!("{}", *result.b);
  19. }
  20.  
  21. result
  22. }
  23. }
  24.  
  25. fn main() {
  26. let a = A::new(10);
  27. unsafe {
  28. println!("{}", *a.b);
  29. }
  30. }
Add Comment
Please, Sign In to add comment