Created
September 22, 2017 09:48
-
-
Save anonymous/f9f5ee5fe961ac052699eaabf2a9ae6c to your computer and use it in GitHub Desktop.
Rust code shared from the playground
This file contains hidden or 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::fmt::Debug; | |
| #[derive(Debug)] | |
| struct Suricata<State> where State: SuricataState + Debug { | |
| work_dir: String, | |
| state: State | |
| } | |
| impl Suricata<Starting> { | |
| fn start(self) -> Suricata<Running> { | |
| Suricata { | |
| work_dir: self.work_dir, | |
| state: Running | |
| } | |
| } | |
| } | |
| trait SuricataState {} | |
| #[derive(Debug)] | |
| struct Starting; | |
| impl SuricataState for Starting {} | |
| #[derive(Debug)] | |
| struct Running; | |
| impl SuricataState for Running {} | |
| fn main() { | |
| let suricata = Suricata { | |
| work_dir: "foo".to_string(), | |
| state: Starting | |
| }; | |
| println!("{:?}", suricata); | |
| println!("{:?}", suricata.start()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment