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(index: 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 index(&self) -> u8

Get the index of the port (port number).

Ports are indexed starting from 1.

§Examples
let my_port = unsafe { SmartPort::new(1) };

assert_eq!(my_port.index(), 1);
source

pub fn connected_type(&self) -> Result<SmartDeviceType, PortError>

Get the type of device currently connected to this port.

§Examples
let my_port = unsafe { SmartPort::new(1) };

println!("Type of device connected to port 1: {:?}", my_port.connected_type()?);
source

pub fn configured_type(&self) -> Result<SmartDeviceType, PortError>

Get the type of device this port is configured as.

§Examples
let my_port = unsafe { SmartPort::new(1) };
let imu = InertialSensor::new(my_port)?;

assert_eq!(my_port.configured_type()?, SmartDeviceType::Imu);

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 PartialEq for SmartPort

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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>,

§

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>,

§

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.