Struct CoapRequest

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

Representation of a CoAP request message.

This struct wraps around the more direct CoapMessage and allows easier definition of typical options used in requests.

Implementations§

Source§

impl CoapRequest

Source

pub fn new( type_: CoapMessageType, code: CoapRequestCode, uri: CoapUri, ) -> Result<CoapRequest, MessageTypeError>

Creates a new CoAP request with the given message type and code.

Returns an error if the given message type is not allowed for CoAP requests (the only allowed message types are CoapMessageType::Con and CoapMessageType::Non) or the request URI is malformed.

Source

pub fn accept(&self) -> Option<ContentFormat>

Returns the “Accept” option value for this request.

Source

pub fn set_accept(&mut self, accept: Option<ContentFormat>)

Sets the “Accept” option value for this request.

This option indicates the acceptable content formats for the response.

See RFC 7252, Section 5.10.4 for more information.

Source

pub fn etag(&self) -> Option<&Vec<ETag>>

Returns the “ETag” option value for this request.

Source

pub fn set_etag(&mut self, etag: Option<Vec<ETag>>)

Sets the “ETag” option value for this request.

This option can be used to request a specific representation of the requested resource.

The server may send an ETag value alongside a response, which the client can then set here to request the given representation.

See RFC 7252, Section 5.10.6 for more information.

Source

pub fn if_match(&self) -> Option<&Vec<CoapMatch>>

Returns the “If-Match” option value for this request.

Source

pub fn set_if_match(&mut self, if_match: Option<Vec<CoapMatch>>)

Sets the “If-Match” option value for this request.

This option indicates a match expression that must be fulfilled in order to perform the request.

See RFC 7252, Section 5.10.8.1 for more information.

Source

pub fn content_format(&self) -> Option<ContentFormat>

Returns the “Content-Format” option value for this request.

Source

pub fn set_content_format(&mut self, content_format: Option<ContentFormat>)

Sets the “Content-Format” option value for this request.

This option indicates the content format of the body of this message. It is not to be confused with the “Accept” option, which indicates the format that the body of the response to this message should have.

See RFC 7252, Section 5.10.3 for more information.

Source

pub fn if_none_match(&self) -> bool

Returns the “If-None-Match” option value of this request.

Source

pub fn set_if_none_match(&mut self, if_none_match: bool)

Sets the “If-None-Match” option value for this request.

This option indicates that no match expression may be fulfilled in order for this request to be fulfilled.

It is usually nonsensical to set this value to true if an If-Match-Expression has been set.

See RFC 7252, Section 5.10.8.2 for more information.

Source

pub fn hop_limit(&self) -> Option<HopLimit>

Returns the “Hop-Limit” option value of this request.

Source

pub fn set_hop_limit(&mut self, hop_limit: Option<HopLimit>)

Sets the “Hop-Limit” option value for this request.

This option is mainly used to prevent proxying loops and specifies the maximum number of proxies that the request may pass.

This option is defined in RFC 8768 and is not part of the main CoAP spec. Some peers may therefore not support this option.

Source

pub fn no_response(&self) -> Option<NoResponse>

Returns the “No-Response” option value for this request.

Source

pub fn set_no_response(&mut self, no_response: Option<NoResponse>)

Sets the “No-Response” option value for this request.

This option indicates that the client performing this request does not wish to receive a response for this request.

This option is defined in RFC 7967 and is not part of the main CoAP spec. Some peers may therefore not support this option.

Source

pub fn observe(&self) -> Option<Observe>

Returns the “Observe” option value for this request.

Source

pub fn set_observe(&mut self, observe: Option<Observe>)

Sets the “Observe” option value for this request.

This option indicates that the client performing this request wishes to be notified of changes to the requested resource.

This option is defined in RFC 7641 and is not part of the main CoAP spec. Some peers may therefore not support this option.

Source

pub fn uri(&self) -> &CoapUri

Returns the CoAP URI that is requested.

Source

pub fn from_message<'a>( pdu: CoapMessage, session: &impl CoapSessionCommon<'a>, ) -> Result<CoapRequest, MessageConversionError>

Parses the given CoapMessage into a CoapRequest.

Returns a MessageConversionError if the provided PDU cannot be parsed into a request.

Source

pub fn into_message(self) -> CoapMessage

Converts this request into a CoapMessage that can be sent over a CoapSession.

Trait Implementations§

Source§

impl Clone for CoapRequest

Source§

fn clone(&self) -> CoapRequest

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 CoapMessageCommon for CoapRequest

Source§

fn set_code<C: Into<CoapMessageCode>>(&mut self, code: C)

Sets the message code of this request.

§Panics

Panics if the provided message code is not a request code.

Source§

fn as_message(&self) -> &CoapMessage

Returns a reference to this message.
Source§

fn as_message_mut(&mut self) -> &mut CoapMessage

Returns a mutable reference to this message.
Source§

fn add_option(&mut self, option: CoapOption)

Add the supplied CoAP option to this message.
Source§

fn clear_options(&mut self)

Clear the list of options that were added to this message using add_option().
Source§

fn options_iter(&self) -> Iter<'_, CoapOption>

Returns an iterator over the options contained in this message.
Source§

fn type_(&self) -> CoapMessageType

Returns the CoAP message type (confirmable, non-confirmable, acknowledgement, rst) of this message.
Source§

fn set_type_(&mut self, type_: CoapMessageType)

Sets the CoAP message type (confirmable, non-confirmable, acknowledgement, rst) of this message.
Source§

fn code(&self) -> CoapMessageCode

Returns the message code of this message. To determine whether the message is a request or response, use CoapMessageCode::try_from() and match for the enum variants.
Source§

fn mid(&self) -> Option<CoapMessageId>

Returns the CoAP message ID for this message.
Source§

fn set_mid(&mut self, mid: Option<CoapMessageId>)

Sets the CoAP message ID for this message.
Source§

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

Returns a reference to the data/body of this message.
Source§

fn set_data<D: Into<Box<[u8]>>>(&mut self, data: Option<D>)

Sets the data/body of this message.
Source§

fn token(&self) -> Option<&[u8]>

Returns the message token.
Source§

fn set_token<D: Into<Box<[u8]>>>(&mut self, token: Option<D>)

Sets the message token. Read more
Source§

impl Debug for CoapRequest

Source§

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

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

impl From<CoapRequest> for CoapMessage

Source§

fn from(val: CoapRequest) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for CoapRequest

Source§

fn eq(&self, other: &CoapRequest) -> 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 Eq for CoapRequest

Source§

impl StructuralPartialEq for CoapRequest

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

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T