eye_hal/
traits.rs

1use crate::control;
2use crate::device;
3use crate::error::Result;
4use crate::stream;
5
6/// Platform context abstraction
7pub trait Context<'a> {
8    /// Device type supported by this platform
9    type Device: Device<'a>;
10
11    /// Returns all devices currently available
12    fn devices(&self) -> Result<Vec<device::Description>>;
13
14    /// Opens a device handle
15    fn open_device(&self, uri: &str) -> Result<Self::Device>;
16}
17
18/// Platform device abstraction
19pub trait Device<'a> {
20    /// Capture stream type created by this device
21    type Stream: Stream<'a>;
22
23    /// Returns the supported streams
24    fn streams(&self) -> Result<Vec<stream::Descriptor>>;
25
26    /// Returns a stream which produces images
27    fn start_stream(&self, desc: &stream::Descriptor) -> Result<Self::Stream>;
28
29    /// Returns the supported controls
30    fn controls(&self) -> Result<Vec<control::Descriptor>>;
31
32    /// Returns the current control value for an ID
33    fn control(&self, id: u32) -> Result<control::State>;
34
35    /// Sets the control value, returns error for incompatible value types
36    fn set_control(&mut self, id: u32, val: &control::State) -> Result<()>;
37}
38
39/// Stream abstraction
40///
41/// A stream is a construct which offers one item at a time. Once the next item is available, the
42/// previous one is discarded and thus not accessible any longer.
43pub trait Stream<'a> {
44    /// Type of the stream elements
45    type Item;
46
47    /// Advances the stream and returns the next item
48    fn next(&'a mut self) -> Option<Self::Item>;
49}