[][src]Struct commodity::CommodityType

pub struct CommodityType {
    pub id: CommodityTypeID,
    pub name: Option<String>,
}

Represents a type of Commodity.

See CommodityTypeID for the primative which is genarally stored and used to refer to a given CommodityType.

Fields

id: CommodityTypeID

Stores 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

impl CommodityType[src]

pub fn new(id: CommodityTypeID, name: Option<String>) -> CommodityType[src]

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);

pub fn from_str<SR: AsRef<str>, SI: Into<String>>(
    id: SR,
    name: SI
) -> Result<CommodityType, CommodityError>
[src]

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

impl Clone for CommodityType[src]

impl Debug for CommodityType[src]

impl<'de> Deserialize<'de> for CommodityType[src]

impl Display for CommodityType[src]

impl Eq for CommodityType[src]

impl<'_> From<&'_ CommodityType> for CommodityTypeID[src]

impl Hash for CommodityType[src]

impl PartialEq<CommodityType> for CommodityType[src]

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 Serialize for CommodityType[src]

impl StructuralEq for CommodityType[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.