Skip to content

Instantly share code, notes, and snippets.

Created September 22, 2017 09:48
Show Gist options
  • Select an option

  • Save anonymous/f9f5ee5fe961ac052699eaabf2a9ae6c to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/f9f5ee5fe961ac052699eaabf2a9ae6c to your computer and use it in GitHub Desktop.
Rust code shared from the playground
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