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

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

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

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

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.