linuxcnc_hal/hal_pin/
mod.rs

1//! HAL pins
2
3#[macro_use]
4mod macros;
5
6mod bidirectional_pin;
7mod hal_pin;
8mod input_pin;
9mod output_pin;
10mod pin_direction;
11
12pub use self::{
13    bidirectional_pin::BidirectionalPin, hal_pin::HalPin, input_pin::InputPin,
14    output_pin::OutputPin,
15};
16use crate::error::StorageError;
17
18/// Readable pin trait
19///
20/// Implemented for any pin that can only be read by a component
21pub trait PinRead: HalPin {
22    /// Get the value of the pin
23    fn value(&self) -> Result<&<Self as HalPin>::Storage, StorageError> {
24        self.storage()
25    }
26}
27
28/// Writable pin trait
29///
30/// Implemented for any pin that can be only written to by a component
31pub trait PinWrite: HalPin {
32    /// Set the value of the pin
33    fn set_value(&self, value: <Self as HalPin>::Storage) -> Result<(), StorageError> {
34        Ok(*self.storage_mut()? = value)
35    }
36}