pub struct CommodityType {
pub id: CommodityTypeID,
pub name: Option<String>,
}Expand description
Represents a type of Commodity.
See CommodityTypeID for the primative which is genarally stored and used to refer to a given CommodityType.
Fields§
§id: CommodityTypeIDStores the id of this commodity type in a fixed length ArrayString, with a maximum length of COMMODITY_TYPE_ID_LENGTH.
name: Option<String>The human readable name of this commodity_type.
Implementations§
Source§impl CommodityType
impl CommodityType
Sourcepub fn new(id: CommodityTypeID, name: Option<String>) -> CommodityType
pub fn new(id: CommodityTypeID, name: Option<String>) -> CommodityType
Create a new CommodityType.
§Example
use std::str::FromStr;
let id = CommodityTypeID::from_str("AUD").unwrap();
let commodity_type = CommodityType::new(
id,
Some(String::from("Australian Dollar"))
);
assert_eq!(id, commodity_type.id);
assert_eq!(Some(String::from("Australian Dollar")), commodity_type.name);Sourcepub fn from_str<SR: AsRef<str>, SI: Into<String>>(
id: SR,
name: SI,
) -> Result<CommodityType, CommodityError>
pub fn from_str<SR: AsRef<str>, SI: Into<String>>( id: SR, name: SI, ) -> Result<CommodityType, CommodityError>
Create a CommodityType from strings, usually for debugging, or unit testing purposes.
id is an array backed string that has a fixed maximum size
of COMMODITY_TYPE_ID_LENGTH. The supplied
string must not exeed this, or a
CommodityError::TooLongCommodityTypeID
will be returned.
§Example
use std::str::FromStr;
let commodity_type = CommodityType::from_str("AUD", "Australian dollar").unwrap();
assert_eq!(CommodityTypeID::from_str("AUD").unwrap(), commodity_type.id);
assert_eq!("Australian dollar", commodity_type.name.unwrap());Trait Implementations§
Source§impl Clone for CommodityType
impl Clone for CommodityType
Source§fn clone(&self) -> CommodityType
fn clone(&self) -> CommodityType
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CommodityType
impl Debug for CommodityType
Source§impl<'de> Deserialize<'de> for CommodityType
impl<'de> Deserialize<'de> for CommodityType
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>,
Source§impl Display for CommodityType
impl Display for CommodityType
Source§impl From<&CommodityType> for CommodityTypeID
impl From<&CommodityType> for CommodityTypeID
Source§fn from(commodity_type: &CommodityType) -> CommodityTypeID
fn from(commodity_type: &CommodityType) -> CommodityTypeID
Source§impl Hash for CommodityType
impl Hash for CommodityType
Source§impl PartialEq for CommodityType
This implementation only checks that the ids match. It assumes
that you will not have logical different commodity types with the
same id but different names.
impl PartialEq for CommodityType
This implementation only checks that the ids match. It assumes that you will not have logical different commodity types with the same id but different names.