Created
July 16, 2019 19:48
-
-
Save rust-play/25f73df3ec28792ba35e9ecc5b8cf9b1 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains 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
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