Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add all elements to Element enum #12

Open
seatonullberg opened this issue Dec 21, 2020 · 0 comments
Open

Add all elements to Element enum #12

seatonullberg opened this issue Dec 21, 2020 · 0 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@seatonullberg
Copy link
Owner

seatonullberg commented Dec 21, 2020

The Element enum currently supports only a minimal set of elements used in testing. All the naturally occurring elements from Hydrogen through Uranium should be implemented. The following snippet shows the existing implementation:

/// Every element on the periodic table.
#[derive(Clone, Copy, Debug, PartialEq, EnumString, Hash, Eq)]
pub enum Element {
/// Hydrogen
H,
/// Helium
He,
/// Boron
B,
/// Nitrogen
N,
/// Oxygen
O,
/// Fluorine
F,
/// Sodium
Na,
/// Magnesium
Mg,
/// Chlorine
Cl,
/// Argon
Ar,
/// Xenon
Xe,
}
impl Element {
/// Returns the atomic mass of the element in amu.
pub const fn mass(&self) -> Float {
match self {
Element::H => 1.008,
Element::He => 4.0026,
Element::B => 10.811,
Element::N => 14.0067,
Element::O => 15.999,
Element::F => 18.998,
Element::Na => 22.989,
Element::Mg => 24.305,
Element::Cl => 35.453,
Element::Ar => 39.948,
Element::Xe => 131.293,
}
}
/// Returns the electronic charge of the element as a multiple of electron charge.
pub const fn charge(&self) -> Float {
match self {
Element::H => 1.0,
Element::He => 0.0,
Element::B => 3.0,
Element::N => -3.0,
Element::O => -2.0,
Element::F => -1.0,
Element::Na => 1.0,
Element::Mg => 2.0,
Element::Cl => -1.0,
Element::Ar => 0.0,
Element::Xe => 0.0,
}
}
/// Returns the atomic number of the element.
pub const fn number(&self) -> u8 {
match self {
Element::H => 1,
Element::He => 2,
Element::B => 5,
Element::N => 7,
Element::O => 8,
Element::F => 9,
Element::Na => 11,
Element::Mg => 12,
Element::Cl => 17,
Element::Ar => 18,
Element::Xe => 54,
}
}
}

@seatonullberg seatonullberg added help wanted Extra attention is needed good first issue Good for newcomers labels Dec 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant