Skip to main content

Device

Trait Device 

Source
pub trait Device {
    // Required methods
    fn id(&self) -> &str;
    async fn connect(&mut self) -> Result<()>;
    async fn disconnect(&mut self) -> Result<()>;
}
Expand description

A connectable physical or virtual device.

Implementors manage the lifecycle of an underlying resource such as a serial port, a network socket, or a vehicle link.

Required Methods§

Source

fn id(&self) -> &str

Returns the stable identifier for this device.

The identifier is expected to remain constant for the lifetime of the device, for example a serial number, MAC address, or vehicle URI.

§Returns

A string slice borrowing the device’s identifier.

Source

async fn connect(&mut self) -> Result<()>

Opens the device and prepares it for use.

§Returns

Ok(()) once the device is connected and ready.

§Errors

Returns Error::Io if the underlying resource cannot be opened, or Error::Transport if a link to the device cannot be established.

Source

async fn disconnect(&mut self) -> Result<()>

Releases the device and any resources it holds.

§Returns

Ok(()) once the device has been disconnected and its resources freed.

§Errors

Returns Error::Io if the underlying resource cannot be released cleanly.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§