Struct CoapResponse

Source
pub struct CoapResponse { /* private fields */ }

Implementations§

Source§

impl CoapResponse

Source

pub fn new( type_: CoapMessageType, code: CoapResponseCode, ) -> Result<CoapResponse, MessageTypeError>

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

Returns an error if the given message type is not allowed for CoAP responses (the allowed message types are CoapMessageType::Con and CoapMessageType::Non and CoapMessageType::Ack).

Source

pub fn max_age(&self) -> Option<MaxAge>

Returns the “Max-Age” option value for this response.

Source

pub fn set_max_age(&mut self, max_age: Option<MaxAge>)

Sets the “Max-Age” option value for this response.

This option indicates the maximum time a response may be cached (in seconds).

See RFC 7252, Section 5.10.5 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 response.

This option indicates the content format of the body of this message.

See RFC 7252, Section 5.10.3 for more information.

Source

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

Returns the “ETag” option value for this request.

Source

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

Sets the “ETag” option value for this response.

This option can be used by clients 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 echo(&self) -> Option<&Echo>

Returns the “Echo” option value for this request.

Source

pub fn set_echo(&mut self, echo: Option<Echo>)

Sets the “Echo” option value for this response.

This option can be used by servers to ensure that a request is recent.

The client should include the provided option value in its next request.

As handling echo options on the client side is done automatically by libcoap, this option is not accessible in [CoapRequest], see man coap_send for more information.

See RFC 9175, Section 2.2 for more information.

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 response.

This option indicates that this response is a notification for a previously requested resource observation.

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 location(&self) -> Option<&CoapUri>

Returns the “Location” option value for this request.

Source

pub fn set_location<U: Into<CoapUri>>( &mut self, uri: Option<U>, ) -> Result<(), OptionValueError>

Sets the “Location-Path” and “Location-Query” option values for this response.

These options indicate a relative URI for a resource created in response of a POST or PUT request.

The supplied URI must be relative to the requested path and must therefore also not contain a scheme, host or port. Also, each path component must be smaller than 255 characters.

If an invalid URI is provided, an OptionValueError is returned

See RFC 7252, Section 5.10.7 for more information.

Source

pub fn into_message(self) -> CoapMessage

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

Source

pub fn from_message( pdu: CoapMessage, ) -> Result<CoapResponse, MessageConversionError>

Parses the given CoapMessage into a CoapResponse.

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

Trait Implementations§

Source§

impl Clone for CoapResponse

Source§

fn clone(&self) -> CoapResponse

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 CoapResponse

Source§

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

Sets the message code of this response.

§Panics

Panics if the provided message code is not a response 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 CoapResponse

Source§

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

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

impl From<CoapResponse> for CoapMessage

Source§

fn from(val: CoapResponse) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for CoapResponse

Source§

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

Source§

impl StructuralPartialEq for CoapResponse

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