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    /* Not included since this just tells us the total number stream types
40     *
41     * Count = sys::rs2_stream_RS2_STREAM_COUNT, */
42}
43
44impl std::fmt::Display for Rs2StreamKind {
45    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46        let string = match self {
47            Rs2StreamKind::Any => "Any",
48            Rs2StreamKind::Depth => "Depth",
49            Rs2StreamKind::Color => "Color",
50            Rs2StreamKind::Infrared => "Infrared",
51            Rs2StreamKind::Fisheye => "Fisheye",
52            Rs2StreamKind::Gyro => "Gyro",
53            Rs2StreamKind::Accel => "Accel",
54            Rs2StreamKind::Gpio => "Gpio",
55            Rs2StreamKind::Pose => "Pose",
56            Rs2StreamKind::Confidence => "Confidence",
57        };
58        write!(f, "{}", string)
59    }
60}
61
62#[cfg(test)]
63mod tests {
64    use super::*;
65    use num_traits::FromPrimitive;
66
67    #[test]
68    fn all_variants_exist() {
69        for i in 0..sys::rs2_stream_RS2_STREAM_COUNT as i32 {
70            assert!(
71                Rs2StreamKind::from_i32(i).is_some(),
72                "Rs2StreamKind variant for ordinal {} does not exist.",
73                i,
74            );
75        }
76    }
77}