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
impl CoapRequest
Sourcepub fn new(
type_: CoapMessageType,
code: CoapRequestCode,
uri: CoapUri,
) -> Result<CoapRequest, MessageTypeError>
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.
Sourcepub fn accept(&self) -> Option<ContentFormat>
pub fn accept(&self) -> Option<ContentFormat>
Returns the “Accept” option value for this request.
Sourcepub fn set_accept(&mut self, accept: Option<ContentFormat>)
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.
Sourcepub fn set_etag(&mut self, etag: Option<Vec<ETag>>)
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.
Sourcepub fn if_match(&self) -> Option<&Vec<CoapMatch>>
pub fn if_match(&self) -> Option<&Vec<CoapMatch>>
Returns the “If-Match” option value for this request.
Sourcepub fn set_if_match(&mut self, if_match: Option<Vec<CoapMatch>>)
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.
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 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.
Sourcepub fn if_none_match(&self) -> bool
pub fn if_none_match(&self) -> bool
Returns the “If-None-Match” option value of this request.
Sourcepub fn set_if_none_match(&mut self, if_none_match: bool)
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.
Sourcepub fn hop_limit(&self) -> Option<HopLimit>
pub fn hop_limit(&self) -> Option<HopLimit>
Returns the “Hop-Limit” option value of this request.
Sourcepub fn set_hop_limit(&mut self, hop_limit: Option<HopLimit>)
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.
Sourcepub fn no_response(&self) -> Option<NoResponse>
pub fn no_response(&self) -> Option<NoResponse>
Returns the “No-Response” option value for this request.
Sourcepub fn set_no_response(&mut self, no_response: Option<NoResponse>)
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.
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 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.
Sourcepub fn from_message<'a>(
pdu: CoapMessage,
session: &impl CoapSessionCommon<'a>,
) -> Result<CoapRequest, MessageConversionError>
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.
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.
Trait Implementations§
Source§impl Clone for CoapRequest
impl Clone for CoapRequest
Source§fn clone(&self) -> CoapRequest
fn clone(&self) -> CoapRequest
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl CoapMessageCommon for CoapRequest
impl CoapMessageCommon for CoapRequest
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 request.
§Panics
Panics if the provided message code is not a request code.