Skip to content

Instantly share code, notes, and snippets.

@tanriol tanriol/test.rs Secret
Created Apr 12, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.