Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. use std::cell::Cell;
  2.  
  3. #[derive(Copy, Clone, Debug)]
  4. enum Pin {
  5.  
  6. P1,
  7. P2,
  8. P3
  9. }
  10.  
  11. struct SharedPins {
  12.  
  13. p1: Pin,
  14. p2: Pin
  15. }
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23. fn main() {
  24.  
  25. let spc = Cell::new(None);
  26. let conf = setup(&spc);
  27. println!("{:?}", conf);
  28. }
  29.  
  30. fn setup(spc: &Cell<Option <SharedPins>>) -> (&Pin, &Pin, Pin) {
  31.  
  32. spc.set(Some(SharedPins{p1: Pin::P1, p2: Pin::P2}));
  33.  
  34.  
  35.  
  36.  
  37. let sp = unsafe {&*(spc.as_ptr() as *mut SharedPins)};
  38.  
  39. (&sp.p1, &sp.p2, Pin::P3)
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement