Struct Message

Source
pub struct Message<'data, const MAX_OPTION_COUNT: usize = { crate::DEFAULT_MAX_OPTION_COUNT }> { /* private fields */ }
Expand description

A CoAP Message. Use this as a builder structure and then encode the message

Implementations§

Source§

impl<'data, const MAX_OPTION_COUNT: usize> Message<'data, MAX_OPTION_COUNT>

Source

pub fn new( message_type: Type, code: Code, message_id: u16, token: Token, options: Vec<CoapOption<'data>, MAX_OPTION_COUNT>, payload: Option<&'data [u8]>, ) -> Self

Initialize with minimum required message parameters.

The Message_Id and the Token are handled internally by CoAP-Zero. Options and a Payload are not required for a valid CoAP Message, but both can be set by the user if needed.

Source

pub fn new_ack(message_id: u16) -> Self

Convenience constructor for empty ACKs (can not be used for piggybacked responses)

Source

pub fn new_rst(message_id: u16) -> Self

Convenience constructor for RSTs

Source

pub fn new_ping(message_id: u16) -> Self

Convenience constructor for pings

Source

pub fn message_type(&self) -> Type

Returns the message type

Source

pub fn code(&self) -> Code

Returns the message code

Source

pub fn message_id(&self) -> u16

Returns the message ID

Source

pub fn token(&self) -> Token

Returns the token

Source

pub fn options(&self) -> &Vec<CoapOption<'_>, MAX_OPTION_COUNT>

Returns a reference to the options vector

Source

pub fn payload(&self) -> Option<&'data [u8]>

Returns a reference to the payload, if any

Source

pub fn is_empty(&self) -> bool

Returns true if the message code is Code::Empty

Source

pub fn is_request(&self) -> bool

Returns true if the message has a code of Code::Request

Source

pub fn is_response(&self) -> bool

Returns true if the message has a code of Code::Response

Trait Implementations§

Source§

impl<'data, const MAX_OPTION_COUNT: usize> Clone for Message<'data, MAX_OPTION_COUNT>

Source§

fn clone(&self) -> Message<'data, MAX_OPTION_COUNT>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'data, const MAX_OPTION_COUNT: usize> Debug for Message<'data, MAX_OPTION_COUNT>

Source§

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

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

impl<'data, const MAX_OPTION_COUNT: usize> PartialEq for Message<'data, MAX_OPTION_COUNT>

Source§

fn eq(&self, other: &Message<'data, MAX_OPTION_COUNT>) -> bool

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

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<'data, const MAX_OPTION_COUNT: usize> TryFrom<EncodedMessage<'data>> for Message<'data, MAX_OPTION_COUNT>

Source§

type Error = Error

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

fn try_from(encoded: EncodedMessage<'data>) -> Result<Self, Error>

Performs the conversion.
Source§

impl<'data, const MAX_OPTION_COUNT: usize> Eq for Message<'data, MAX_OPTION_COUNT>

Source§

impl<'data, const MAX_OPTION_COUNT: usize> StructuralPartialEq for Message<'data, MAX_OPTION_COUNT>

Auto Trait Implementations§

§

impl<'data, const MAX_OPTION_COUNT: usize> Freeze for Message<'data, MAX_OPTION_COUNT>

§

impl<'data, const MAX_OPTION_COUNT: usize> RefUnwindSafe for Message<'data, MAX_OPTION_COUNT>

§

impl<'data, const MAX_OPTION_COUNT: usize> Send for Message<'data, MAX_OPTION_COUNT>

§

impl<'data, const MAX_OPTION_COUNT: usize> Sync for Message<'data, MAX_OPTION_COUNT>

§

impl<'data, const MAX_OPTION_COUNT: usize> Unpin for Message<'data, MAX_OPTION_COUNT>

§

impl<'data, const MAX_OPTION_COUNT: usize> UnwindSafe for Message<'data, MAX_OPTION_COUNT>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.