Struct SmartPort

Source
pub struct SmartPort { /* private fields */ }
Expand description

Represents a Smart Port on a V5 Brain

Implementations§

Source§

impl SmartPort

Source

pub const unsafe fn new(number: u8) -> Self

Creates a new Smart Port on a specified index.

§Safety

Creating new SmartPorts 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) };
Source

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);
Source

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);
}
Source

pub fn validate_type( &self, device_type: SmartDeviceType, ) -> Result<(), PortError>

Verify that a device type is currently plugged into this port, returning an appropriate PortError if not available.

§Errors

Returns a PortError if there is not a device of the specified type in this port.

Trait Implementations§

Source§

impl Debug for SmartPort

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<AdiExpander> for SmartPort

Source§

fn from(device: AdiExpander) -> Self

Converts to this type from the input type.
Source§

impl From<AiVisionSensor> for SmartPort

Source§

fn from(val: AiVisionSensor) -> Self

Converts to this type from the input type.
Source§

impl From<DistanceSensor> for SmartPort

Source§

fn from(device: DistanceSensor) -> Self

Converts to this type from the input type.
Source§

impl From<Electromagnet> for SmartPort

Source§

fn from(device: Electromagnet) -> Self

Converts to this type from the input type.
Source§

impl From<GpsSensor> for SmartPort

Source§

fn from(device: GpsSensor) -> Self

Converts to this type from the input type.
Source§

impl From<InertialSensor> for SmartPort

Source§

fn from(device: InertialSensor) -> Self

Converts to this type from the input type.
Source§

impl From<Motor> for SmartPort

Source§

fn from(device: Motor) -> Self

Converts to this type from the input type.
Source§

impl From<OpticalSensor> for SmartPort

Source§

fn from(device: OpticalSensor) -> Self

Converts to this type from the input type.
Source§

impl From<RadioLink> for SmartPort

Source§

fn from(device: RadioLink) -> Self

Converts to this type from the input type.
Source§

impl From<RotationSensor> for SmartPort

Source§

fn from(device: RotationSensor) -> Self

Converts to this type from the input type.
Source§

impl From<SerialPort> for SmartPort

Source§

fn from(device: SerialPort) -> Self

Converts to this type from the input type.
Source§

impl From<VisionSensor> for SmartPort

Source§

fn from(device: VisionSensor) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for SmartPort

Source§

fn eq(&self, other: &SmartPort) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for SmartPort

Source§

impl StructuralPartialEq for SmartPort

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.