Skip to content

Instantly share code, notes, and snippets.

@iancormac84
Last active April 19, 2018 23:50
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 iancormac84/1548bcc7823b16e9d8fdfc6592bd6ba1 to your computer and use it in GitHub Desktop.
Save iancormac84/1548bcc7823b16e9d8fdfc6592bd6ba1 to your computer and use it in GitHub Desktop.
Example of Chemical Element Modelling
pub trait UniqueProperties {
const ATOMIC_NUMBER: u32;
const SYMBOL: &'static str;
const PERIOD: u8;
}
pub struct Hydrogen;
impl UniqueProperties for Hydrogen {
const ATOMIC_NUMBER: u32 = 1;
const SYMBOL: &'static str = "H";
const PERIOD: u8 = 1;
}
pub struct Atom<A: UniqueProperties>(A);
//Doesn't compile. How can I make the associated constants useable inside this trait implementation?
impl<A, B> PartialEq<Atom<B>> for Atom<A>
where A: UniqueProperties, B: UniqueProperties {
fn eq(&self, other: &Atom<B>) -> bool {
self.0::SYMBOL == other.0::SYMBOL
}
}
fn main() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment