Guest User

Untitled

a guest
Jan 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. use std::marker::PhantomData;
  2.  
  3. #[derive(Debug)]
  4. enum ONE{}
  5. #[derive(Debug)]
  6. enum TWO{}
  7.  
  8. #[derive(Debug)]
  9. struct X<R> {
  10. i: i32,
  11. _state: PhantomData<R>
  12. }
  13.  
  14. fn g<R>() -> X<R> {
  15. return X{
  16. i: 42,
  17. _state: PhantomData
  18. };
  19. }
  20.  
  21. fn into_one() -> X<ONE> {
  22. println!("Returning a ONE");
  23. g()
  24. }
  25.  
  26. fn into_two() -> X<TWO> {
  27. println!("Returning a TWO");
  28. g()
  29. }
  30.  
  31. fn main() {
  32. let a: X<ONE> = g();
  33. let b: X<TWO> = g();
  34. let c: X<ONE> = into_one();
  35. let d: X<TWO> = into_two();
  36. println!("{:#?} {:#?} {:#?} {:#?}", a, b, c, d);
  37. }
Add Comment
Please, Sign In to add comment