Skip to main content

nominal_api/conjure/objects/scout/compute/api/
enum_bucket.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 EnumBucket {
16    #[builder(default, map(key(type = i32), value(type = conjure_object::SafeLong)))]
17    #[serde(
18        rename = "histogram",
19        skip_serializing_if = "std::collections::BTreeMap::is_empty",
20        default
21    )]
22    histogram: std::collections::BTreeMap<i32, conjure_object::SafeLong>,
23    #[builder(custom(type = super::CompactEnumPoint, convert = Box::new))]
24    #[serde(rename = "firstPoint")]
25    first_point: Box<super::CompactEnumPoint>,
26    #[builder(
27        default,
28        custom(
29            type = impl
30            Into<Option<super::CompactEnumPoint>>,
31            convert = |v|v.into().map(Box::new)
32        )
33    )]
34    #[serde(rename = "lastPoint", skip_serializing_if = "Option::is_none", default)]
35    last_point: Option<Box<super::CompactEnumPoint>>,
36}
37impl EnumBucket {
38    /// Constructs a new instance of the type.
39    #[inline]
40    pub fn new(first_point: super::CompactEnumPoint) -> Self {
41        Self::builder().first_point(first_point).build()
42    }
43    /// The map of values within the bucket to their frequency.
44    #[inline]
45    pub fn histogram(
46        &self,
47    ) -> &std::collections::BTreeMap<i32, conjure_object::SafeLong> {
48        &self.histogram
49    }
50    #[inline]
51    pub fn first_point(&self) -> &super::CompactEnumPoint {
52        &*self.first_point
53    }
54    /// Will be empty if the bucket only has a single point.
55    #[inline]
56    pub fn last_point(&self) -> Option<&super::CompactEnumPoint> {
57        self.last_point.as_ref().map(|o| &**o)
58    }
59}