pub struct CoapResponse { /* private fields */ }
Implementations§
Source§impl CoapResponse
impl CoapResponse
Sourcepub fn new(
type_: CoapMessageType,
code: CoapResponseCode,
) -> Result<CoapResponse, MessageTypeError>
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).
Sourcepub fn set_max_age(&mut self, max_age: Option<MaxAge>)
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.
Sourcepub fn content_format(&self) -> Option<ContentFormat>
pub fn content_format(&self) -> Option<ContentFormat>
Returns the “Content-Format” option value for this request.
Sourcepub fn set_content_format(&mut self, content_format: Option<ContentFormat>)
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.
Sourcepub fn set_etag(&mut self, etag: Option<ETag>)
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.
Sourcepub fn set_echo(&mut self, echo: Option<Echo>)
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.
Sourcepub fn set_observe(&mut self, observe: Option<Observe>)
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.
Sourcepub fn location(&self) -> Option<&CoapUri>
pub fn location(&self) -> Option<&CoapUri>
Returns the “Location” option value for this request.
Sourcepub fn set_location<U: Into<CoapUri>>(
&mut self,
uri: Option<U>,
) -> Result<(), OptionValueError>
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.
Sourcepub fn into_message(self) -> CoapMessage
pub fn into_message(self) -> CoapMessage
Converts this request into a CoapMessage that can be sent over a CoapSession.
Sourcepub fn from_message(
pdu: CoapMessage,
) -> Result<CoapResponse, MessageConversionError>
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
impl Clone for CoapResponse
Source§fn clone(&self) -> CoapResponse
fn clone(&self) -> CoapResponse
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl CoapMessageCommon for CoapResponse
impl CoapMessageCommon for CoapResponse
Source§fn set_code<C: Into<CoapMessageCode>>(&mut self, code: C)
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.