Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::marker::PhantomData;
- #[derive(Debug)]
- enum ONE{}
- #[derive(Debug)]
- enum TWO{}
- #[derive(Debug)]
- struct X<R> {
- i: i32,
- _state: PhantomData<R>
- }
- fn g<R>() -> X<R> {
- return X{
- i: 42,
- _state: PhantomData
- };
- }
- fn into_one() -> X<ONE> {
- println!("Returning a ONE");
- g()
- }
- fn into_two() -> X<TWO> {
- println!("Returning a TWO");
- g()
- }
- fn main() {
- let a: X<ONE> = g();
- let b: X<TWO> = g();
- let c: X<ONE> = into_one();
- let d: X<TWO> = into_two();
- println!("{:#?} {:#?} {:#?} {:#?}", a, b, c, d);
- }
Add Comment
Please, Sign In to add comment