re_types/components/
aggregation_policy.rs1#![allow(unused_imports)]
5#![allow(unused_parens)]
6#![allow(clippy::clone_on_copy)]
7#![allow(clippy::cloned_instead_of_copied)]
8#![allow(clippy::map_flatten)]
9#![allow(clippy::needless_question_mark)]
10#![allow(clippy::new_without_default)]
11#![allow(clippy::redundant_closure)]
12#![allow(clippy::too_many_arguments)]
13#![allow(clippy::too_many_lines)]
14#![allow(non_camel_case_types)]
15
16use ::re_types_core::try_serialize_field;
17use ::re_types_core::SerializationResult;
18use ::re_types_core::{ComponentBatch as _, SerializedComponentBatch};
19use ::re_types_core::{ComponentDescriptor, ComponentName};
20use ::re_types_core::{DeserializationError, DeserializationResult};
21
22#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Default)]
28#[repr(u8)]
29pub enum AggregationPolicy {
30 Off = 1,
32
33 Average = 2,
35
36 Max = 3,
38
39 Min = 4,
41
42 #[default]
46 MinMax = 5,
47
48 MinMaxAverage = 6,
50}
51
52impl ::re_types_core::Component for AggregationPolicy {
53 #[inline]
54 fn descriptor() -> ComponentDescriptor {
55 ComponentDescriptor::new("rerun.components.AggregationPolicy")
56 }
57}
58
59::re_types_core::macros::impl_into_cow!(AggregationPolicy);
60
61impl ::re_types_core::Loggable for AggregationPolicy {
62 #[inline]
63 fn arrow_datatype() -> arrow::datatypes::DataType {
64 #![allow(clippy::wildcard_imports)]
65 use arrow::datatypes::*;
66 DataType::UInt8
67 }
68
69 fn to_arrow_opt<'a>(
70 data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
71 ) -> SerializationResult<arrow::array::ArrayRef>
72 where
73 Self: Clone + 'a,
74 {
75 #![allow(clippy::wildcard_imports)]
76 #![allow(clippy::manual_is_variant_and)]
77 use ::re_types_core::{arrow_helpers::as_array_ref, Loggable as _, ResultExt as _};
78 use arrow::{array::*, buffer::*, datatypes::*};
79 Ok({
80 let (somes, data0): (Vec<_>, Vec<_>) = data
81 .into_iter()
82 .map(|datum| {
83 let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into);
84 let datum = datum.map(|datum| *datum as u8);
85 (datum.is_some(), datum)
86 })
87 .unzip();
88 let data0_validity: Option<arrow::buffer::NullBuffer> = {
89 let any_nones = somes.iter().any(|some| !*some);
90 any_nones.then(|| somes.into())
91 };
92 as_array_ref(PrimitiveArray::<UInt8Type>::new(
93 ScalarBuffer::from(
94 data0
95 .into_iter()
96 .map(|v| v.unwrap_or_default())
97 .collect::<Vec<_>>(),
98 ),
99 data0_validity,
100 ))
101 })
102 }
103
104 fn from_arrow_opt(
105 arrow_data: &dyn arrow::array::Array,
106 ) -> DeserializationResult<Vec<Option<Self>>>
107 where
108 Self: Sized,
109 {
110 #![allow(clippy::wildcard_imports)]
111 use ::re_types_core::{arrow_zip_validity::ZipValidity, Loggable as _, ResultExt as _};
112 use arrow::{array::*, buffer::*, datatypes::*};
113 Ok(arrow_data
114 .as_any()
115 .downcast_ref::<UInt8Array>()
116 .ok_or_else(|| {
117 let expected = Self::arrow_datatype();
118 let actual = arrow_data.data_type().clone();
119 DeserializationError::datatype_mismatch(expected, actual)
120 })
121 .with_context("rerun.components.AggregationPolicy#enum")?
122 .into_iter()
123 .map(|typ| match typ {
124 Some(1) => Ok(Some(Self::Off)),
125 Some(2) => Ok(Some(Self::Average)),
126 Some(3) => Ok(Some(Self::Max)),
127 Some(4) => Ok(Some(Self::Min)),
128 Some(5) => Ok(Some(Self::MinMax)),
129 Some(6) => Ok(Some(Self::MinMaxAverage)),
130 None => Ok(None),
131 Some(invalid) => Err(DeserializationError::missing_union_arm(
132 Self::arrow_datatype(),
133 "<invalid>",
134 invalid as _,
135 )),
136 })
137 .collect::<DeserializationResult<Vec<Option<_>>>>()
138 .with_context("rerun.components.AggregationPolicy")?)
139 }
140}
141
142impl std::fmt::Display for AggregationPolicy {
143 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
144 match self {
145 Self::Off => write!(f, "Off"),
146 Self::Average => write!(f, "Average"),
147 Self::Max => write!(f, "Max"),
148 Self::Min => write!(f, "Min"),
149 Self::MinMax => write!(f, "MinMax"),
150 Self::MinMaxAverage => write!(f, "MinMaxAverage"),
151 }
152 }
153}
154
155impl ::re_types_core::reflection::Enum for AggregationPolicy {
156 #[inline]
157 fn variants() -> &'static [Self] {
158 &[
159 Self::Off,
160 Self::Average,
161 Self::Max,
162 Self::Min,
163 Self::MinMax,
164 Self::MinMaxAverage,
165 ]
166 }
167
168 #[inline]
169 fn docstring_md(self) -> &'static str {
170 match self {
171 Self::Off => "No aggregation.",
172 Self::Average => "Average all points in the range together.",
173 Self::Max => "Keep only the maximum values in the range.",
174 Self::Min => "Keep only the minimum values in the range.",
175 Self::MinMax => {
176 "Keep both the minimum and maximum values in the range.\n\nThis will yield two aggregated points instead of one, effectively creating a vertical line."
177 }
178 Self::MinMaxAverage => {
179 "Find both the minimum and maximum values in the range, then use the average of those."
180 }
181 }
182 }
183}
184
185impl ::re_byte_size::SizeBytes for AggregationPolicy {
186 #[inline]
187 fn heap_size_bytes(&self) -> u64 {
188 0
189 }
190
191 #[inline]
192 fn is_pod() -> bool {
193 true
194 }
195}