realsense_rust/kind/
stream_kind.rs

1//! Enumeration describing the possible kinds of streams a stream profile can describe.
2//!
3//! Streams are different types of data provided by RealSense devices.
4
5use num_derive::{FromPrimitive, ToPrimitive};
6use realsense_sys as sys;
7
8/// The enumeration of possible stream kinds.
9///
10/// These are typically used when configuring a [`pipeline`](crate::pipeline::InactivePipeline), or
11/// obtained from a [`StreamProfile`](crate::stream_profile::StreamProfile).
12#[repr(i32)]
13#[derive(FromPrimitive, ToPrimitive, Debug, Clone, Copy, PartialEq, Eq, Hash)]
14pub enum Rs2StreamKind {
15    /// Stream kind key to tell librealsense2 to pick the best suited stream kind.
16    ///
17    /// Unlike the other format entries, `Any` is used primarily when setting up streams in the
18    /// config / pipeline. If you pass this, librealsense2 will pick the best suited (default)
19    /// stream kinds for a given sensor.
20    Any = sys::rs2_stream_RS2_STREAM_ANY as i32,
21    /// Native stream of depth data produced by RealSense device
22    Depth = sys::rs2_stream_RS2_STREAM_DEPTH as i32,
23    /// Native stream of color data captured by RealSense device
24    Color = sys::rs2_stream_RS2_STREAM_COLOR as i32,
25    /// Native stream of infrared data captured by RealSense device
26    Infrared = sys::rs2_stream_RS2_STREAM_INFRARED as i32,
27    /// Native stream of fish-eye (wide) data captured from the dedicated motion camera
28    Fisheye = sys::rs2_stream_RS2_STREAM_FISHEYE as i32,
29    /// Native stream of gyroscope motion data produced by RealSense device
30    Gyro = sys::rs2_stream_RS2_STREAM_GYRO as i32,
31    /// Native stream of accelerometer motion data produced by RealSense device
32    Accel = sys::rs2_stream_RS2_STREAM_ACCEL as i32,
33    /// Signals from external device connected through GPIO
34    Gpio = sys::rs2_stream_RS2_STREAM_GPIO as i32,
35    /// 6DoF pose data, calculated by RealSense device
36    Pose = sys::rs2_stream_RS2_STREAM_POSE as i32,
37    /// 4-bit per pixel depth confidence values
38    Confidence = sys::rs2_stream_RS2_STREAM_CONFIDENCE as i32,
39    /// Native stream of combined motion data (incl. accel & gyro)
40    Motion = sys::rs2_stream_RS2_STREAM_MOTION as i32,
41    /* Not included since this just tells us the total number stream types
42     *
43     * Count = sys::rs2_stream_RS2_STREAM_COUNT, */
44}
45
46impl std::fmt::Display for Rs2StreamKind {
47    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
48        let string = match self {
49            Rs2StreamKind::Any => "Any",
50            Rs2StreamKind::Depth => "Depth",
51            Rs2StreamKind::Color => "Color",
52            Rs2StreamKind::Infrared => "Infrared",
53            Rs2StreamKind::Fisheye => "Fisheye",
54            Rs2StreamKind::Gyro => "Gyro",
55            Rs2StreamKind::Accel => "Accel",
56            Rs2StreamKind::Gpio => "Gpio",
57            Rs2StreamKind::Pose => "Pose",
58            Rs2StreamKind::Confidence => "Confidence",
59            Rs2StreamKind::Motion => "Motion",
60        };
61        write!(f, "{}", string)
62    }
63}
64
65#[cfg(test)]
66mod tests {
67    use super::*;
68    use num_traits::FromPrimitive;
69
70    #[test]
71    fn all_variants_exist() {
72        for i in 0..sys::rs2_stream_RS2_STREAM_COUNT as i32 {
73            assert!(
74                Rs2StreamKind::from_i32(i).is_some(),
75                "Rs2StreamKind variant for ordinal {} does not exist.",
76                i,
77            );
78        }
79    }
80}