Struct libcoap_rs::message::response::CoapResponse
source · pub struct CoapResponse { /* private fields */ }
Implementations
sourceimpl 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_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<&CoapResponseLocation>
pub fn location(&self) -> Option<&CoapResponseLocation>
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
sourceimpl Clone for CoapResponse
impl Clone for CoapResponse
sourcefn clone(&self) -> CoapResponse
fn clone(&self) -> CoapResponse
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl CoapMessageCommon for CoapResponse
impl CoapMessageCommon for CoapResponse
sourcefn 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.