Created
February 21, 2019 21:59
-
-
Save rust-play/26787ee59109f7abc3349c4854fdfbe5 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::marker::PhantomData; | |
struct Intermediate<T> { | |
marker: PhantomData<T> | |
} | |
struct Start {} | |
struct Baseline {} | |
trait HasBaseline{} | |
impl HasBaseline for Baseline {} | |
struct PNet<T> where T: HasBaseline { | |
marker: PhantomData<T> | |
} | |
impl<T: HasBaseline> HasBaseline for PNet<T> {} | |
struct PAvailable<T> where T: HasBaseline { | |
marker: PhantomData<T> | |
} | |
impl<T: HasBaseline> HasBaseline for PAvailable<T> {} | |
impl Intermediate<Start> { | |
fn add_baseline(self) -> Intermediate<Baseline> { | |
Intermediate { | |
marker: PhantomData | |
} | |
} | |
} | |
impl<T> Intermediate<T> where T: HasBaseline { | |
fn add_p_net(self) -> Intermediate<PNet<T>> { | |
Intermediate { marker: PhantomData } | |
} | |
fn add_p_available(self) -> Intermediate<PAvailable<T>> { | |
Intermediate { marker: PhantomData } | |
} | |
} | |
fn main() { | |
let i: Intermediate<Start> = Intermediate { | |
marker: PhantomData | |
}; | |
i.add_baseline() | |
.add_p_net() | |
.add_p_available() | |
.add_p_net(); // We can use it again!!!! | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment