pub struct Compound { /* private fields */ }Expand description
A named chemical compound with formula and lightweight descriptors.
Implementations§
Source§impl Compound
impl Compound
Sourcepub fn new(
name: &str,
formula: ChemicalFormula,
) -> Result<Self, CompoundValidationError>
pub fn new( name: &str, formula: ChemicalFormula, ) -> Result<Self, CompoundValidationError>
Creates a compound from a name and formula.
§Errors
Returns CompoundValidationError::EmptyName when name is empty after trimming.
Sourcepub const fn name(&self) -> &CompoundName
pub const fn name(&self) -> &CompoundName
Returns the primary compound name.
Sourcepub const fn compound_formula(&self) -> &CompoundFormula
pub const fn compound_formula(&self) -> &CompoundFormula
Returns the compound formula wrapper.
Sourcepub const fn common_name(&self) -> Option<&CommonName>
pub const fn common_name(&self) -> Option<&CommonName>
Returns the optional common name.
Sourcepub const fn systematic_name(&self) -> Option<&SystematicName>
pub const fn systematic_name(&self) -> Option<&SystematicName>
Returns the optional systematic name.
Sourcepub const fn empirical_formula(&self) -> Option<&EmpiricalFormula>
pub const fn empirical_formula(&self) -> Option<&EmpiricalFormula>
Returns the optional empirical formula.
Sourcepub const fn molecular_formula(&self) -> Option<&MolecularFormula>
pub const fn molecular_formula(&self) -> Option<&MolecularFormula>
Returns the optional molecular formula.
Sourcepub fn kinds(&self) -> &[CompoundKind]
pub fn kinds(&self) -> &[CompoundKind]
Returns compound kind labels in insertion order.
Sourcepub fn identifiers(&self) -> &[CompoundIdentifier]
pub fn identifiers(&self) -> &[CompoundIdentifier]
Returns compound identifiers in insertion order.
Sourcepub fn with_kind(self, kind: CompoundKind) -> Self
pub fn with_kind(self, kind: CompoundKind) -> Self
Adds a kind label if it is not already present.
Sourcepub fn with_common_name(self, common_name: CommonName) -> Self
pub fn with_common_name(self, common_name: CommonName) -> Self
Sets the common name from a validated value.
Sourcepub fn try_with_common_name(
self,
common_name: &str,
) -> Result<Self, CompoundValidationError>
pub fn try_with_common_name( self, common_name: &str, ) -> Result<Self, CompoundValidationError>
Sets the common name after validation.
§Errors
Returns CompoundValidationError::EmptyCommonName when common_name is empty after trimming.
Sourcepub fn with_systematic_name(self, systematic_name: SystematicName) -> Self
pub fn with_systematic_name(self, systematic_name: SystematicName) -> Self
Sets the systematic name from a validated value.
Sourcepub fn try_with_systematic_name(
self,
systematic_name: &str,
) -> Result<Self, CompoundValidationError>
pub fn try_with_systematic_name( self, systematic_name: &str, ) -> Result<Self, CompoundValidationError>
Sets the systematic name after validation.
§Errors
Returns CompoundValidationError::EmptySystematicName when systematic_name is empty after trimming.
Sourcepub fn with_empirical_formula(self, formula: EmpiricalFormula) -> Self
pub fn with_empirical_formula(self, formula: EmpiricalFormula) -> Self
Sets the empirical formula.
Sourcepub fn with_molecular_formula(self, formula: MolecularFormula) -> Self
pub fn with_molecular_formula(self, formula: MolecularFormula) -> Self
Sets the molecular formula.
Sourcepub fn try_with_identifier(
self,
identifier: CompoundIdentifier,
) -> Result<Self, CompoundValidationError>
pub fn try_with_identifier( self, identifier: CompoundIdentifier, ) -> Result<Self, 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.