Struct Compound
pub struct Compound { /* private fields */ }Expand description
A named chemical compound with formula and lightweight descriptors.
Implementations§
§impl Compound
impl Compound
pub fn new(
name: &str,
formula: ChemicalFormula,
) -> Result<Compound, CompoundValidationError>
pub fn new( name: &str, formula: ChemicalFormula, ) -> Result<Compound, CompoundValidationError>
Creates a compound from a name and formula.
§Errors
Returns CompoundValidationError::EmptyName when name is empty after trimming.
pub const fn name(&self) -> &CompoundName
pub const fn name(&self) -> &CompoundName
Returns the primary compound name.
pub fn formula(&self) -> &ChemicalFormula
pub fn formula(&self) -> &ChemicalFormula
Returns the primary formula.
pub const fn compound_formula(&self) -> &CompoundFormula
pub const fn compound_formula(&self) -> &CompoundFormula
Returns the compound formula wrapper.
pub const fn common_name(&self) -> Option<&CommonName>
pub const fn common_name(&self) -> Option<&CommonName>
Returns the optional common name.
pub const fn systematic_name(&self) -> Option<&SystematicName>
pub const fn systematic_name(&self) -> Option<&SystematicName>
Returns the optional systematic name.
pub const fn empirical_formula(&self) -> Option<&EmpiricalFormula>
pub const fn empirical_formula(&self) -> Option<&EmpiricalFormula>
Returns the optional empirical formula.
pub const fn molecular_formula(&self) -> Option<&MolecularFormula>
pub const fn molecular_formula(&self) -> Option<&MolecularFormula>
Returns the optional molecular formula.
pub fn kinds(&self) -> &[CompoundKind]
pub fn kinds(&self) -> &[CompoundKind]
Returns compound kind labels in insertion order.
pub fn identifiers(&self) -> &[CompoundIdentifier]
pub fn identifiers(&self) -> &[CompoundIdentifier]
Returns compound identifiers in insertion order.
pub fn with_kind(self, kind: CompoundKind) -> Compound
pub fn with_kind(self, kind: CompoundKind) -> Compound
Adds a kind label if it is not already present.
pub fn with_common_name(self, common_name: CommonName) -> Compound
pub fn with_common_name(self, common_name: CommonName) -> Compound
Sets the common name from a validated value.
pub fn try_with_common_name(
self,
common_name: &str,
) -> Result<Compound, CompoundValidationError>
pub fn try_with_common_name( self, common_name: &str, ) -> Result<Compound, CompoundValidationError>
Sets the common name after validation.
§Errors
Returns CompoundValidationError::EmptyCommonName when common_name is empty after trimming.
pub fn with_systematic_name(self, systematic_name: SystematicName) -> Compound
pub fn with_systematic_name(self, systematic_name: SystematicName) -> Compound
Sets the systematic name from a validated value.
pub fn try_with_systematic_name(
self,
systematic_name: &str,
) -> Result<Compound, CompoundValidationError>
pub fn try_with_systematic_name( self, systematic_name: &str, ) -> Result<Compound, CompoundValidationError>
Sets the systematic name after validation.
§Errors
Returns CompoundValidationError::EmptySystematicName when systematic_name is empty after trimming.
pub fn with_empirical_formula(self, formula: EmpiricalFormula) -> Compound
pub fn with_empirical_formula(self, formula: EmpiricalFormula) -> Compound
Sets the empirical formula.
pub fn with_molecular_formula(self, formula: MolecularFormula) -> Compound
pub fn with_molecular_formula(self, formula: MolecularFormula) -> Compound
Sets the molecular formula.
pub fn try_with_identifier(
self,
identifier: CompoundIdentifier,
) -> Result<Compound, CompoundValidationError>
pub fn try_with_identifier( self, identifier: CompoundIdentifier, ) -> Result<Compound, CompoundValidationError>
Adds an identifier if it is not already present.
§Errors
This method currently cannot fail because CompoundIdentifier values are validated at
construction, but it returns Result so builder chains can stay consistently fallible.