pub struct SmartPort { /* private fields */ }
Expand description
Represents a Smart Port on a V5 Brain
Implementations§
Source§impl SmartPort
impl SmartPort
Sourcepub const unsafe fn new(number: u8) -> Self
pub const unsafe fn new(number: u8) -> Self
Creates a new Smart Port on a specified index.
§Safety
Creating new SmartPort
s is inherently unsafe due to the possibility of constructing
more than one device on the same port index allowing multiple mutable references to
the same hardware device. This violates rust’s borrow checked guarantees. Prefer using
Peripherals
to register devices if possible.
§Examples
// Create a new Smart Port at index 1.
// This is unsafe! You are responsible for ensuring that only one device registered on a
// single port index.
let my_port = unsafe { SmartPort::new(1) };
Sourcepub const fn number(&self) -> u8
pub const fn number(&self) -> u8
Returns the number of the port.
Ports are numbered starting from 1.
§Examples
let my_port = unsafe { SmartPort::new(1) };
assert_eq!(my_port.number(), 1);
Sourcepub fn device_type(&self) -> Option<SmartDeviceType>
pub fn device_type(&self) -> Option<SmartDeviceType>
Returns the type of device currently connected to this port, or None
if no device is connected.
§Examples
let my_port = unsafe { SmartPort::new(1) };
if let Some(device_type) = my_port.device_type() {
println!("Type of device connected to port 1: {:?}", device_type);
}
Sourcepub fn validate_type(
&self,
device_type: SmartDeviceType,
) -> Result<(), PortError>
pub fn validate_type( &self, device_type: SmartDeviceType, ) -> Result<(), PortError>
Trait Implementations§
Source§impl From<AdiExpander> for SmartPort
impl From<AdiExpander> for SmartPort
Source§fn from(device: AdiExpander) -> Self
fn from(device: AdiExpander) -> Self
Converts to this type from the input type.
Source§impl From<AiVisionSensor> for SmartPort
impl From<AiVisionSensor> for SmartPort
Source§fn from(val: AiVisionSensor) -> Self
fn from(val: AiVisionSensor) -> Self
Converts to this type from the input type.
Source§impl From<DistanceSensor> for SmartPort
impl From<DistanceSensor> for SmartPort
Source§fn from(device: DistanceSensor) -> Self
fn from(device: DistanceSensor) -> Self
Converts to this type from the input type.
Source§impl From<Electromagnet> for SmartPort
impl From<Electromagnet> for SmartPort
Source§fn from(device: Electromagnet) -> Self
fn from(device: Electromagnet) -> Self
Converts to this type from the input type.
Source§impl From<InertialSensor> for SmartPort
impl From<InertialSensor> for SmartPort
Source§fn from(device: InertialSensor) -> Self
fn from(device: InertialSensor) -> Self
Converts to this type from the input type.
Source§impl From<OpticalSensor> for SmartPort
impl From<OpticalSensor> for SmartPort
Source§fn from(device: OpticalSensor) -> Self
fn from(device: OpticalSensor) -> Self
Converts to this type from the input type.
Source§impl From<RotationSensor> for SmartPort
impl From<RotationSensor> for SmartPort
Source§fn from(device: RotationSensor) -> Self
fn from(device: RotationSensor) -> Self
Converts to this type from the input type.
Source§impl From<SerialPort> for SmartPort
impl From<SerialPort> for SmartPort
Source§fn from(device: SerialPort) -> Self
fn from(device: SerialPort) -> Self
Converts to this type from the input type.
Source§impl From<VisionSensor> for SmartPort
impl From<VisionSensor> for SmartPort
Source§fn from(device: VisionSensor) -> Self
fn from(device: VisionSensor) -> Self
Converts to this type from the input type.
impl Eq for SmartPort
impl StructuralPartialEq for SmartPort
Auto Trait Implementations§
impl Freeze for SmartPort
impl RefUnwindSafe for SmartPort
impl Send for SmartPort
impl Sync for SmartPort
impl Unpin for SmartPort
impl UnwindSafe for SmartPort
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more