Last active
April 19, 2018 23:50
-
-
Save iancormac84/1548bcc7823b16e9d8fdfc6592bd6ba1 to your computer and use it in GitHub Desktop.
Example of Chemical Element Modelling
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
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