re_types/blueprint/components/
link_axis.rs

1// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/rust/api.rs
2// Based on "crates/store/re_types/definitions/rerun/blueprint/components/link_axis.fbs".
3
4#![allow(unused_braces)]
5#![allow(unused_imports)]
6#![allow(unused_parens)]
7#![allow(clippy::clone_on_copy)]
8#![allow(clippy::cloned_instead_of_copied)]
9#![allow(clippy::map_flatten)]
10#![allow(clippy::needless_question_mark)]
11#![allow(clippy::new_without_default)]
12#![allow(clippy::redundant_closure)]
13#![allow(clippy::too_many_arguments)]
14#![allow(clippy::too_many_lines)]
15#![allow(non_camel_case_types)]
16
17use ::re_types_core::try_serialize_field;
18use ::re_types_core::SerializationResult;
19use ::re_types_core::{ComponentBatch as _, SerializedComponentBatch};
20use ::re_types_core::{ComponentDescriptor, ComponentType};
21use ::re_types_core::{DeserializationError, DeserializationResult};
22
23/// **Component**: How should the horizontal/X/time axis be linked across multiple plots
24#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Default)]
25#[repr(u8)]
26pub enum LinkAxis {
27    /// The axis is independent from all other plots.
28    #[default]
29    Independent = 1,
30
31    /// Link to all other plots that also have this options set.
32    LinkToGlobal = 2,
33}
34
35impl ::re_types_core::Component for LinkAxis {
36    #[inline]
37    fn name() -> ComponentType {
38        "rerun.blueprint.components.LinkAxis".into()
39    }
40}
41
42::re_types_core::macros::impl_into_cow!(LinkAxis);
43
44impl ::re_types_core::Loggable for LinkAxis {
45    #[inline]
46    fn arrow_datatype() -> arrow::datatypes::DataType {
47        #![allow(clippy::wildcard_imports)]
48        use arrow::datatypes::*;
49        DataType::UInt8
50    }
51
52    fn to_arrow_opt<'a>(
53        data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
54    ) -> SerializationResult<arrow::array::ArrayRef>
55    where
56        Self: Clone + 'a,
57    {
58        #![allow(clippy::wildcard_imports)]
59        #![allow(clippy::manual_is_variant_and)]
60        use ::re_types_core::{arrow_helpers::as_array_ref, Loggable as _, ResultExt as _};
61        use arrow::{array::*, buffer::*, datatypes::*};
62        Ok({
63            let (somes, data0): (Vec<_>, Vec<_>) = data
64                .into_iter()
65                .map(|datum| {
66                    let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into);
67                    let datum = datum.map(|datum| *datum as u8);
68                    (datum.is_some(), datum)
69                })
70                .unzip();
71            let data0_validity: Option<arrow::buffer::NullBuffer> = {
72                let any_nones = somes.iter().any(|some| !*some);
73                any_nones.then(|| somes.into())
74            };
75            as_array_ref(PrimitiveArray::<UInt8Type>::new(
76                ScalarBuffer::from(
77                    data0
78                        .into_iter()
79                        .map(|v| v.unwrap_or_default())
80                        .collect::<Vec<_>>(),
81                ),
82                data0_validity,
83            ))
84        })
85    }
86
87    fn from_arrow_opt(
88        arrow_data: &dyn arrow::array::Array,
89    ) -> DeserializationResult<Vec<Option<Self>>>
90    where
91        Self: Sized,
92    {
93        #![allow(clippy::wildcard_imports)]
94        use ::re_types_core::{arrow_zip_validity::ZipValidity, Loggable as _, ResultExt as _};
95        use arrow::{array::*, buffer::*, datatypes::*};
96        Ok(arrow_data
97            .as_any()
98            .downcast_ref::<UInt8Array>()
99            .ok_or_else(|| {
100                let expected = Self::arrow_datatype();
101                let actual = arrow_data.data_type().clone();
102                DeserializationError::datatype_mismatch(expected, actual)
103            })
104            .with_context("rerun.blueprint.components.LinkAxis#enum")?
105            .into_iter()
106            .map(|typ| match typ {
107                Some(1) => Ok(Some(Self::Independent)),
108                Some(2) => Ok(Some(Self::LinkToGlobal)),
109                None => Ok(None),
110                Some(invalid) => Err(DeserializationError::missing_union_arm(
111                    Self::arrow_datatype(),
112                    "<invalid>",
113                    invalid as _,
114                )),
115            })
116            .collect::<DeserializationResult<Vec<Option<_>>>>()
117            .with_context("rerun.blueprint.components.LinkAxis")?)
118    }
119}
120
121impl std::fmt::Display for LinkAxis {
122    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
123        match self {
124            Self::Independent => write!(f, "Independent"),
125            Self::LinkToGlobal => write!(f, "LinkToGlobal"),
126        }
127    }
128}
129
130impl ::re_types_core::reflection::Enum for LinkAxis {
131    #[inline]
132    fn variants() -> &'static [Self] {
133        &[Self::Independent, Self::LinkToGlobal]
134    }
135
136    #[inline]
137    fn docstring_md(self) -> &'static str {
138        match self {
139            Self::Independent => "The axis is independent from all other plots.",
140            Self::LinkToGlobal => "Link to all other plots that also have this options set.",
141        }
142    }
143}
144
145impl ::re_byte_size::SizeBytes for LinkAxis {
146    #[inline]
147    fn heap_size_bytes(&self) -> u64 {
148        0
149    }
150
151    #[inline]
152    fn is_pod() -> bool {
153        true
154    }
155}