Struct CoapRequestHandler

Source
pub struct CoapRequestHandler<D: Any + ?Sized + Debug> { /* private fields */ }
Expand description

A handler for CoAP requests on a resource.

This handler can be associated with a CoapResource in order to be called when a request for the associated resource and the provided method arrives. The handler is then able to generate and send a response to the request accordingly.

§Creating a CoapRequestHandler

There are multiple ways to create a CoapRequestHandler:

For method 2, the provided handler has to be a FnMut(&mut D, &mut CoapServerSession, &CoapRequest, CoapResponse), while for the other two methods, the handler has to be a FnMut(&CoapResource<D>, &mut CoapServerSession, &CoapRequest, CoapResponse), with the following arguments:

  • Either the associated CoapResource or the user data depending on the type of handler. Getting the user data directly without the associated resource has the advantage that it is easy to pass a method as a handler, while getting the CoapResource gives you the option to manipulate the resource (you can still get the user data from the resource using CoapResource::user_data.
  • The server-side session with the peer this request was received from. You may want to store or retrieve additional information about the peer using CoapSessionCommon::set_app_data() and CoapSessionCommon::app_data().
  • The incoming CoapRequest received from the client.
  • A prepared CoapResponse instance that is already set to the correct token value to be treated as a response to the request by the client.

Implementations§

Source§

impl<D: 'static + ?Sized + Debug> CoapRequestHandler<D>

Source

pub fn new<F: 'static + FnMut(&mut D, &mut CoapServerSession<'_>, &CoapRequest, CoapResponse)>( handler: F, ) -> CoapRequestHandler<D>

Creates a new CoapResourceHandler with the given function as the handler function to call.

Source

pub fn new_resource_ref<F: 'static + FnMut(&CoapResource<D>, &mut CoapServerSession<'_>, &CoapRequest, CoapResponse)>( handler: F, ) -> CoapRequestHandler<D>

Creates a new CoapResourceHandler with the given function as the handler function to call.

In contrast to CoapRequestHandler::new, the handler for this function is not provided with a direct reference to the user data, but instead with a reference to the associated CoapResource. This way, you can perform actions on the resource directly (e.g., notify observers).

Source

pub unsafe fn from_raw_handler( raw_handler: unsafe extern "C" fn(resource: *mut coap_resource_t, session: *mut coap_session_t, incoming_pdu: *const coap_pdu_t, query: *const coap_string_t, response_pdu: *mut coap_pdu_t), ) -> CoapRequestHandler<D>

Creates a new request handler using the given raw handler function.

The handler function provided here is called directly by libcoap.

§Safety

The handler function must not modify the user data value inside of the provided raw resource in a way that would break normal handler functions. Also, neither the resource nor the session may be freed by calling coap_delete_resource or coap_session_release.

Trait Implementations§

Source§

impl<D: 'static + ?Sized + Debug> Debug for CoapRequestHandler<D>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<D> Freeze for CoapRequestHandler<D>
where D: ?Sized,

§

impl<D> !RefUnwindSafe for CoapRequestHandler<D>

§

impl<D> !Send for CoapRequestHandler<D>

§

impl<D> !Sync for CoapRequestHandler<D>

§

impl<D> Unpin for CoapRequestHandler<D>
where D: Unpin + ?Sized,

§

impl<D> !UnwindSafe for CoapRequestHandler<D>

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> 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, 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