Element

Struct Element 

Source
pub struct Element {
    pub count: usize,
    /* private fields */
}
Expand description

An individual element. Containing an element from the periodic table and the count of how many there are.

Eg: O2

Fields§

§count: usize

How many of this element there are. In O2 the count will be 2 and in 2NO3 it will be 3

Implementations§

Source§

impl Element

Source

pub fn parse(input: &str) -> Result<Self, ElementError>

Parse an element from a str

§Examples
use chem_eq::{Element, error::ElementError};

let el = Element::parse("O2");
assert!(el.is_ok());

let el = Element::parse("H2O");
assert_eq!(el.unwrap_err(), ElementError::TooMuchInput("O".to_string()));

Methods from Deref<Target = MendeleevElement>§

Source

pub fn atomic_number(&self) -> u32

Returns the element’s atomic number, i.e., the number of protons in its nucleus.

use mendeleev::Element;
assert_eq!(Element::H.atomic_number(), 1);
assert_eq!(Element::Og.atomic_number(), 118);
Source

pub fn atomic_radius(&self) -> Option<f64>

Returns the element’s empirically measured atomic radius in pm, if available.

use mendeleev::Element;
assert_eq!(Element::H.atomic_radius(), Some(25.0));
Source

pub fn atomic_weight(&self) -> AtomicWeight

Returns the element’s Standard Atomic Weight, if applicable, or its mass number otherwise.

use mendeleev::{Element, AtomicWeight};

assert_eq!(Element::H.atomic_weight(),
AtomicWeight::Interval{range: 1.0078..=1.0082, conventional: 1.008});
assert_eq!(Element::Og.atomic_weight(), AtomicWeight::MassNumber{number: 294});
Source

pub fn cpk_color(&self) -> Option<Color>

Returns the color for the element in the CPK convention.

use mendeleev::{Element, Color};

assert_eq!(Element::H.cpk_color(), Some(Color{r: 255, g: 255, b: 255}));
assert_eq!(Element::Og.cpk_color(), None);
assert_eq!(Element::Au.cpk_color(), Some(Color{r: 218, g: 165, b: 32}));
Source

pub fn group(&self) -> Option<Group>

Returns the element’s group in the periodic table, if any.

use mendeleev::{Element, Group};
assert_eq!(Element::H.group(), Some(Group::IA));
assert_eq!(Element::Og.group(), Some(Group::VIIIA));
assert_eq!(Element::U.group(), None);
Source

pub fn jmol_color(&self) -> Option<Color>

Returns the color for the element in the jmol software

use mendeleev::{Element, Color};

assert_eq!(Element::H.jmol_color(), Some(Color{r: 255, g: 255, b: 255}));
assert_eq!(Element::Og.jmol_color(), None);
assert_eq!(Element::Au.jmol_color(), Some(Color{r: 255, g: 209, b: 35}));
Source

pub fn name(&self) -> &'static str

Returns the name of the element in English.

use mendeleev::Element;
assert_eq!(Element::H.name(), "Hydrogen");
Source

pub fn period(&self) -> u32

Returns the element’s period number in the periodic table.

use mendeleev::Element;
assert_eq!(Element::H.period(), 1);
assert_eq!(Element::Og.period(), 7);
Source

pub fn symbol(&self) -> &'static str

Returns the symbol for the element

use mendeleev::Element;
assert_eq!(Element::H.symbol(), "H");
Source

pub fn year_discovered(&self) -> YearDiscovered

The year in which the element was discovered, if known.

use mendeleev::{Element, YearDiscovered};

assert_eq!(Element::H.year_discovered(), YearDiscovered::Known(1766));
assert_eq!(Element::Og.year_discovered(), YearDiscovered::Known(2002));
assert_eq!(Element::Au.year_discovered(), YearDiscovered::Ancient);
Source

pub fn melting_point(&self) -> Option<f64>

Returns the element’s melting point in Kelvin, if known.

use mendeleev::Element;
assert_eq!(Element::H.melting_point(), Some(14.01));
assert_eq!(Element::C.melting_point(), Some(3820.0));
assert_eq!(Element::Og.melting_point(), None);
Source

pub fn boiling_point(&self) -> Option<f64>

Returns the element’s boiling point in Kelvin, if known.

use mendeleev::Element;
assert_eq!(Element::H.boiling_point(), Some(20.28));
assert_eq!(Element::C.boiling_point(), Some(5100.0));
assert_eq!(Element::Og.boiling_point(), None);
Source

pub fn fusion_heat(&self) -> Option<f64>

Returns the element’s fusion heat in kJ/mol, if known.

use mendeleev::Element;
assert_eq!(Element::H.fusion_heat(), Some(0.117));
assert_eq!(Element::Og.fusion_heat(), None);
Source

pub fn evaporation_heat(&self) -> Option<f64>

Returns the element’s evaporation heat in kJ/mol, if known.

use mendeleev::Element;
assert_eq!(Element::H.evaporation_heat(), Some(0.904));
Source

pub fn electronic_configuration(&self) -> ElectronicConfiguration

Returns the element’s electronic configuration.

use mendeleev::{Element, SubshellLabel};

let configuration = Element::Li.electronic_configuration();
assert_eq!(configuration.noble_gas, Some(Element::He));
assert_eq!(configuration.valence_subshells[0].shell_number, 2);
assert_eq!(configuration.valence_subshells[0].subshell_label, SubshellLabel::S);
assert_eq!(configuration.valence_subshells[0].number_of_electrons, 1);
Source

pub fn discoverers(&self) -> Option<&'static [&'static str]>

Returns the persons and/or institutions involved in the discovery of the element, if known.

use mendeleev::Element;

assert_eq!(Element::H.discoverers(), Some(["Henry Cavendish"].as_slice()));
assert_eq!(Element::He.discoverers(), Some(["Sir William Ramsey", "Nils Langet", "P.T.Cleve"].as_slice()));
assert_eq!(Element::Og.discoverers(), Some(["Joint Institute for Nuclear Research"].as_slice()));
assert_eq!(Element::Au.discoverers(), None);
Source

pub fn discovery_location(&self) -> Option<&'static [&'static str]>

Returns the location (country, in most cases) where the element was discovered, if known. There can be multiple locations if it was an international effort or if multiple teams discovered or isolated the element independently.

use mendeleev::Element;

assert_eq!(Element::H.discovery_location(), Some(["England"].as_slice()));
assert_eq!(Element::He.discovery_location(), Some(["Scotland", "Sweden"].as_slice()));
assert_eq!(Element::Og.discovery_location(), Some(["Russia"].as_slice()));
assert_eq!(Element::Au.discovery_location(), None);
Source

pub fn oxidation_states( &self, category: OxidationStateCategory, ) -> &'static [i8]

Returns the element’s oxidation states for the given category.

§Example
use mendeleev::{Element, OxidationStateCategory::{Main, Extended, All}};

assert_eq!(Element::N.oxidation_states(Main), [-3, 3, 5]);
assert_eq!(Element::N.oxidation_states(Extended), [-2, -1, 0, 1, 2, 4]);
assert_eq!(Element::N.oxidation_states(All), [-3, -2, -1, 0, 1, 2, 3, 4, 5]);

Trait Implementations§

Source§

impl Clone for Element

Source§

fn clone(&self) -> Element

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Element

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Element

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Deref for Element

Source§

type Target = Element

The resulting type after dereferencing.
Source§

fn deref(&self) -> &'static Self::Target

Dereferences the value.
Source§

impl Display for Element

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Ord for Element

Source§

fn cmp(&self, other: &Element) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Element

Source§

fn eq(&self, other: &Element) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Element

Source§

fn partial_cmp(&self, other: &Element) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Element

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Element

Source§

impl StructuralPartialEq for Element

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.