Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub trait State {}
- pub struct Fun;
- impl State for Fun {}
- pub struct Sad;
- impl State for Sad {}
- pub struct J<T: State> {
- s: T
- }
- impl J<Sad> {
- fn new() -> J<Sad> {
- J{s: Sad}
- }
- }
- impl <T: State> J<T> {
- fn change<TT: State>(self, t: TT) -> J<TT> {
- J { s: t}
- }
- }
- pub trait Funny {
- fn fun(&mut self);
- }
- pub struct JuJu<T: State> { /// don't want to have type parameter here
- j: J<T>
- }
- impl <T: State> Funny for JuJu<T> {
- fn fun(&mut self) {
- self.j = self.j.change(Fun)
- }
- }
- fn main() {
- println!("Hello, world!");
- }
Add Comment
Please, Sign In to add comment