Skip to content

Instantly share code, notes, and snippets.

@tanriol

tanriol/test.rs Secret

Created April 12, 2017 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanriol/4b6be207f8fc66211050d722e3a96e5c to your computer and use it in GitHub Desktop.
Save tanriol/4b6be207f8fc66211050d722e3a96e5c to your computer and use it in GitHub Desktop.
trait Handler {
fn handle(&mut self, &str) -> &str;
}
#[derive(Debug)]
struct TestHandle {
uri: String,
value: Option<String>,
}
impl Handler for TestHandle {
fn handle(&mut self, s: &str) -> &str {
self.value = Some(format!("via {}", s));
self.value.as_ref().unwrap()
}
}
struct A<S: Handler> {
name: String,
handler: S,
}
fn main() {
let mut handler = TestHandle {
uri: "/test".into(),
value: None,
};
let mut cont = A {
name: "runner".into(),
handler: handler,
};
println!("{}", cont.handler.handle("abc"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment