Trait RemoteEndpoint

Source
pub trait RemoteEndpoint {
    type SocketAddr: SocketAddrExt;
    type InboundContext: InboundContext<SocketAddr = Self::SocketAddr>;

    // Required methods
    fn uri(&self) -> UriBuf;
    fn scheme(&self) -> &'static str;
    fn remove_host_option(&mut self);
    fn clone_using_rel_ref(&self, uri: &RelRef) -> Self;
    fn send<'a, R, SD>(
        &'a self,
        send_desc: SD,
    ) -> BoxFuture<'_, Result<R, Error>>
       where SD: SendDesc<Self::InboundContext, R> + 'a,
             R: Send + 'a;
    fn send_to<'a, R, SD, UF>(
        &'a self,
        path: UF,
        send_desc: SD,
    ) -> BoxFuture<'_, Result<R, Error>>
       where SD: SendDesc<Self::InboundContext, R> + 'a,
             R: Send + 'a,
             UF: AsRef<RelRef>;
}
Expand description

An object that represents a remote CoAP endpoint with a default, overridable path.

§Example

// Create a remote endpoint instance to represent the
// device we wish to interact with.
let remote_endpoint = local_endpoint
    .remote_endpoint_from_uri(uri!("coap://coap.me"))
    .unwrap(); // Will only fail if the URI scheme or authority is unrecognizable

// Create a future that sends a request to a specific path
// on the remote endpoint, collecting any blocks in the response
// and returning `Ok(OwnedImmutableMessage)` upon success.
let future = remote_endpoint.send_to(
    rel_ref!("large"),
    CoapRequest::get()       // This is a CoAP GET request
        .accept(ContentFormat::TEXT_PLAIN_UTF8) // We only want plaintext
        .block2(Some(Default::default()))       // Enable block2 processing
        .emit_successful_collected_response()                 // Collect all blocks into a single message
);

// Wait for the final result and print it.
println!("result: {:?}", future.await.unwrap());

Required Associated Types§

Source

type SocketAddr: SocketAddrExt

The SocketAddr type to use with this local endpoint. This is usually simply std::net::SocketAddr, but may be different in some cases (like for CoAP-SMS endpoints).

Source

type InboundContext: InboundContext<SocketAddr = Self::SocketAddr>

Type used by closure that is passed into send(), representing the context for the response.

Required Methods§

Source

fn uri(&self) -> UriBuf

Returns a UriBuf describing the underlying destination of this remote endpoint.

Source

fn scheme(&self) -> &'static str

Returns a string slice containing the scheme for this RemoteEndpoint.

Source

fn remove_host_option(&mut self)

Prevents this remote endpoint from including a Uri-Host option.

Source

fn clone_using_rel_ref(&self, uri: &RelRef) -> Self

Creates a clone of this RemoteEndpoint with a different relative path.

Source

fn send<'a, R, SD>(&'a self, send_desc: SD) -> BoxFuture<'_, Result<R, Error>>
where SD: SendDesc<Self::InboundContext, R> + 'a, R: Send + 'a,

Uses send_desc to send a request to the endpoint and path described by this RemoteEndpoint instance.

Source

fn send_to<'a, R, SD, UF>( &'a self, path: UF, send_desc: SD, ) -> BoxFuture<'_, Result<R, Error>>
where SD: SendDesc<Self::InboundContext, R> + 'a, R: Send + 'a, UF: AsRef<RelRef>,

Uses send_desc to send a request to the given relative path on the endpoint described by this RemoteEndpoint instance.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§