Skip to main content

nominal_api/conjure/objects/scout/compute/api/
enum_to_numeric_series.rs

1/// Maps an enumerated series to a numeric series by mapping each string value to a double.
2#[derive(
3    Debug,
4    Clone,
5    conjure_object::serde::Serialize,
6    conjure_object::serde::Deserialize,
7    conjure_object::private::DeriveWith
8)]
9#[serde(crate = "conjure_object::serde")]
10#[derive_with(PartialEq, Eq, PartialOrd, Ord, Hash)]
11#[conjure_object::private::staged_builder::staged_builder]
12#[builder(crate = conjure_object::private::staged_builder, update, inline)]
13pub struct EnumToNumericSeries {
14    #[builder(custom(type = super::EnumSeries, convert = Box::new))]
15    #[serde(rename = "input")]
16    input: Box<super::EnumSeries>,
17    #[builder(
18        default,
19        map(key(type = String, into), value(type = super::DoubleConstant))
20    )]
21    #[serde(
22        rename = "mapping",
23        skip_serializing_if = "std::collections::BTreeMap::is_empty",
24        default
25    )]
26    mapping: std::collections::BTreeMap<String, super::DoubleConstant>,
27    #[builder(
28        default,
29        custom(
30            type = impl
31            Into<Option<super::DoubleConstant>>,
32            convert = |v|v.into().map(Box::new)
33        )
34    )]
35    #[serde(rename = "defaultValue", skip_serializing_if = "Option::is_none", default)]
36    default_value: Option<Box<super::DoubleConstant>>,
37}
38impl EnumToNumericSeries {
39    /// Constructs a new instance of the type.
40    #[inline]
41    pub fn new(input: super::EnumSeries) -> Self {
42        Self::builder().input(input).build()
43    }
44    #[inline]
45    pub fn input(&self) -> &super::EnumSeries {
46        &*self.input
47    }
48    /// The mapping from enum values to doubles.
49    #[inline]
50    pub fn mapping(&self) -> &std::collections::BTreeMap<String, super::DoubleConstant> {
51        &self.mapping
52    }
53    /// The value to use for enum values not present in the mapping. If not specified, points with unmapped
54    /// enum values will be dropped.
55    #[inline]
56    pub fn default_value(&self) -> Option<&super::DoubleConstant> {
57        self.default_value.as_ref().map(|o| &**o)
58    }
59}