pub struct Compound {
pub elements: Vec<Element>,
pub coefficient: usize,
pub state: Option<State>,
pub concentration: f32,
}Expand description
An inidiviual compound. Containing some elements and a coefficient.
Eg: 2Fe2O3
Fields§
§elements: Vec<Element>The elements of a compound
coefficient: usizeThe coefficient of the whole compound
state: Option<State>The state of the compound
concentration: f32The concentration in M (mol/L) of the compound
Implementations§
Source§impl Compound
impl Compound
Sourcepub fn get_units(&self, volume: f32) -> f64
pub fn get_units(&self, volume: f32) -> f64
Get the formula units, atoms or molecules of a compound
§Examples
use chem_eq::{Equation, AVAGADRO_CONSTANT};
let mut eq = Equation::new("H2 + O2 -> H2O").unwrap();
eq.set_concentration_by_name("H2", 1.0).unwrap();
eq.set_volume(1.0);
let cmp = eq.iter_compounds().next().unwrap();
assert_eq!(cmp.get_units(eq.volume().unwrap()), AVAGADRO_CONSTANT);Sourcepub fn parse(input: &str) -> Result<Self, CompoundError>
pub fn parse(input: &str) -> Result<Self, CompoundError>
Parse a compound from str
§Examples
use chem_eq::{Compound, error::CompoundError};
let cmp = Compound::parse("Fe2O3");
assert!(cmp.is_ok());
let cmp = Compound::parse("Fe2O3 + O2");
assert_eq!(cmp.unwrap_err(), CompoundError::TooMuchInput(" + O2".to_string()));Sourcepub fn add_unit(&mut self, volume: f32, addend: isize)
pub fn add_unit(&mut self, volume: f32, addend: isize)
Add to the formula units, atoms or molecules of a compound
§Examples
use chem_eq::{Equation, AVAGADRO_CONSTANT};
let mut eq = Equation::new("H2 + O2 -> H2O").unwrap();
eq.set_concentration_by_name("H2", 1.0).unwrap();
eq.set_volume(1.0);
let volume = eq.volume().unwrap();
let cmp = eq.get_compound_by_name_mut("H2").unwrap();
cmp.add_unit(volume, 1);
assert_eq!(cmp.get_units(volume), AVAGADRO_CONSTANT + 1.0);Trait Implementations§
Source§impl<'de> Deserialize<'de> for Compound
impl<'de> Deserialize<'de> for Compound
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Compound
impl RefUnwindSafe for Compound
impl Send for Compound
impl Sync for Compound
impl Unpin for Compound
impl UnwindSafe for Compound
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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