realsense_rust/
kind.rs

1//! Contains commonly used enumerations and configuration types used across the crate.
2//!
3//! The `Kind` module holds a variety of types useful across realsense-rust APIs as transient
4//! values. The vast majority of types in this module are enums, which map to C-style enums in the
5//! lower-level `realsense-sys` bindings.
6//!
7//! # Architecture
8//!
9//! The low-level bindings for librealsense2 in `realsense-sys` represent the C-style enums as
10//! `u32` constants. They are wrapped / transformed into fully qualified types here so as to
11//! increase type safety across the API.
12//!
13//! All of these "wrapper" enums in Rust implement the [`ToPrimitive`](num_traits::ToPrimitive) and
14//! [`FromPrimitive`](num_traits::FromPrimitive) traits from the `num_traits` crate. If you need to
15//! access the original enum value, you can do so with the following code:
16//!
17//! ```rust
18//! use num_traits::ToPrimitive;
19//! use realsense_rust::kind::Rs2Extension;
20//!
21//! let ext = Rs2Extension::ColorSensor;
22//! println!("The extension is: {}", ext.to_u32().unwrap());
23//! ```
24//!
25//! In practice, most of the time you shouldn't need to wrap or unwrap `u32` values, and the API
26//! should never spit one out at you.
27//!
28//! ## What happened to `COUNT`?
29//!
30//! If you read through the librealsense2 C-API, you'll find that every enumeration has a "count"
31//! entry. Placing a "count" entry at the end of a C-style enum is a common pattern used to be able
32//! to iterate over every possible enum variant. This works because C treats every enum variant as
33//! a distinct `u32` value, instead of a distinct variant of a type. In this crate, we take the
34//! approach that this is unlikely to be something that is undertaken, so we don't provide any
35//! direct means to iterate through every value of each enum variant.
36//!
37//! If you truly need to do this, let us know! There are crates that make this possible and
38//! integrate well with native Rust iterators, but we have chosen to avoid the extra depedencies
39//! for this crate.
40//!
41//! If you need a workaround, you can always use the lower-level `realsense-sys` API:
42//!
43//! ```rust
44//! use num_traits::FromPrimitive;
45//! use realsense_sys as sys;
46//! use realsense_rust::kind::Rs2CameraInfo;
47//!
48//! for i in 0..sys::rs2_camera_info_RS2_CAMERA_INFO_COUNT as i32 {
49//!     println!(
50//!         "The enum variant {:?} corresponds to the i32 value {}",
51//!         Rs2CameraInfo::from_i32(i).unwrap(),
52//!         i,
53//!     );
54//! }
55//! ```
56//!
57
58mod camera_info;
59mod color_scheme;
60mod distortion_model;
61mod exception;
62mod extension;
63mod format;
64mod frame_metadata;
65mod hole_filling;
66mod option;
67mod persistence_control;
68mod product_line;
69mod stream_kind;
70mod timestamp_domain;
71
72pub use camera_info::Rs2CameraInfo;
73pub use color_scheme::ColorScheme;
74pub use distortion_model::Rs2DistortionModel;
75pub use exception::Rs2Exception;
76pub use extension::{
77    Rs2Extension, DEVICE_EXTENSIONS, FILTER_EXTENSIONS, FRAME_EXTENSIONS, MISC_EXTENSIONS,
78    PROFILE_EXTENSIONS, SENSOR_EXTENSIONS,
79};
80pub use format::Rs2Format;
81pub use frame_metadata::Rs2FrameMetadata;
82pub use hole_filling::HoleFillingMode;
83pub use option::{OptionSetError, Rs2Option, Rs2OptionRange};
84pub use persistence_control::PersistenceControl;
85pub use product_line::Rs2ProductLine;
86pub use stream_kind::Rs2StreamKind;
87pub use timestamp_domain::Rs2TimestampDomain;