Skip to main content

nominal_api/conjure/objects/scout/units/api/
unit.rs

1#[derive(
2    Debug,
3    Clone,
4    conjure_object::serde::Serialize,
5    conjure_object::serde::Deserialize,
6    PartialEq,
7    Eq,
8    PartialOrd,
9    Ord,
10    Hash
11)]
12#[serde(crate = "conjure_object::serde")]
13#[conjure_object::private::staged_builder::staged_builder]
14#[builder(crate = conjure_object::private::staged_builder, update, inline)]
15pub struct Unit {
16    #[builder(default, into)]
17    #[serde(rename = "name", skip_serializing_if = "Option::is_none", default)]
18    name: Option<super::UnitName>,
19    #[serde(rename = "symbol")]
20    symbol: super::UnitSymbol,
21    #[builder(default, into)]
22    #[serde(rename = "property", skip_serializing_if = "Option::is_none", default)]
23    property: Option<super::UnitProperty>,
24    #[builder(
25        default,
26        custom(
27            type = impl
28            Into<Option<super::UnitDimension>>,
29            convert = |v|v.into().map(Box::new)
30        )
31    )]
32    #[serde(rename = "dimension", skip_serializing_if = "Option::is_none", default)]
33    dimension: Option<Box<super::UnitDimension>>,
34    #[serde(rename = "system")]
35    system: super::UnitSystem,
36}
37impl Unit {
38    /// Constructs a new instance of the type.
39    #[inline]
40    pub fn new(symbol: super::UnitSymbol, system: super::UnitSystem) -> Self {
41        Self::builder().symbol(symbol).system(system).build()
42    }
43    #[inline]
44    pub fn name(&self) -> Option<&super::UnitName> {
45        self.name.as_ref().map(|o| &*o)
46    }
47    #[inline]
48    pub fn symbol(&self) -> &super::UnitSymbol {
49        &self.symbol
50    }
51    /// Empty if no property is available. If two units measure different properties, it is not possible to
52    /// convert between them.
53    #[inline]
54    pub fn property(&self) -> Option<&super::UnitProperty> {
55        self.property.as_ref().map(|o| &*o)
56    }
57    /// The physical dimensions in terms of the base units of the system. It is only possible to convert units if
58    /// they have the same dimension. Empty if the unit is a base unit.
59    #[inline]
60    pub fn dimension(&self) -> Option<&super::UnitDimension> {
61        self.dimension.as_ref().map(|o| &**o)
62    }
63    #[inline]
64    pub fn system(&self) -> &super::UnitSystem {
65        &self.system
66    }
67}