Skip to main content

CoapTransport

Struct CoapTransport 

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

A CoAP client that implements the core [Transport] trait.

A transport is created disconnected; connect binds the socket and spawns the background task that decodes inbound datagrams for the life of the connection. Observe notifications are queued and read with recv.

Implementations§

Source§

impl CoapTransport

Source

pub fn new(config: CoapConfig) -> Self

Creates a transport from the given configuration without connecting.

§Arguments
  • config - the server connection settings.
§Returns

A disconnected transport ready for connect.

Source

pub fn is_connected(&self) -> bool

Reports whether the transport currently holds a bound socket.

§Returns

true once connect has succeeded and before disconnect is called.

Source

pub async fn recv(&mut self) -> Result<Option<Message>>

Awaits the next notification from an observed resource.

§Returns

Some(message) for the next queued notification, or None once the background task has stopped and no further messages will arrive.

§Errors

Returns [Error::Closed] if the transport is not connected.

Source

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

Closes the socket and stops the background task.

Calling this on a transport that is not connected is a no-op.

§Returns

Ok(()) once the background task has been stopped and the socket released.

§Errors

This call is best-effort and currently always returns Ok(()).

Trait Implementations§

Source§

impl Transport for CoapTransport

Source§

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

Establishes the connection to the broker, peer, or bus. Read more
Source§

async fn send(&mut self, topic: &str, payload: &[u8]) -> Result<()>

Publishes a payload to a topic. Read more
Source§

async fn subscribe(&mut self, topic: &str) -> Result<()>

Subscribes to a topic so that matching payloads are routed to this transport. Read more

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.