Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Sessionv1 {
- pub some_field: bool,
- pub some_field2: bool
- }
- enum Session<T: SessionTrait> {
- V1(Sessionv1),
- Whatever(T),
- }
- impl<NotFinSession> Session<NotFinSession>
- where NotFinSession: SessionTrait {
- pub fn set_some_field(&self, _val: bool) {
- }
- pub fn finalize(self) -> Result<Session::<FinSession>, ()> {
- match self {
- Session::V1(v) => Ok(Session::<FinSession>::V1(v)),
- _ => Err(()),
- }
- }
- }
- impl<FinSession> Session<FinSession>
- where FinSession: SessionTrait {
- pub fn set_some_field2(&self, _val: bool) {
- }
- }
- impl<FinSession> Session<FinSession>
- where FinSession: SessionTrait {
- }
- trait SessionTrait {
- }
- struct FinSession {
- }
- impl SessionTrait for FinSession {
- }
- struct NotFinSession {
- }
- impl SessionTrait for NotFinSession {
- }
- pub fn main() {
- let session = Session::<NotFinSession>::V1(Sessionv1{some_field: false, some_field2: false});
- session.set_some_field(false);
- let fin_session: Session<FinSession> = session.finalize().unwrap();
- fin_session.set_some_field2(true);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement