Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created July 16, 2019 19:48
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 rust-play/25f73df3ec28792ba35e9ecc5b8cf9b1 to your computer and use it in GitHub Desktop.
Save rust-play/25f73df3ec28792ba35e9ecc5b8cf9b1 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
trait Key {
fn key() -> &'static str;
}
trait Model where Self: Key {
fn get() {
println!("Getting {}", Self::key());
}
}
struct Object { }
impl Key for Object {
fn key() -> &'static str {
"object"
}
}
impl Model for Object { }
struct Thing { }
impl Key for Thing {
fn key() -> &'static str {
"thing"
}
}
impl Model for Thing { }
fn main() {
Object::get();
Thing::get();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment