[][src]Trait async_coap::RemoteEndpoint

pub trait RemoteEndpoint {
    type SocketAddr: SocketAddrExt;
    type InboundContext: InboundContext<SocketAddr = Self::SocketAddr>;
    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>
; }

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());

Associated Types

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

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

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

Loading content...

Required methods

fn uri(&self) -> UriBuf

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

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

Returns a string slice containing the scheme for this RemoteEndpoint.

fn remove_host_option(&mut self)

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

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

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

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.

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.

Loading content...

Implementors

impl RemoteEndpoint for NullRemoteEndpoint[src]

type SocketAddr = SocketAddr

type InboundContext = NullInboundContext

impl<US: AsyncDatagramSocket> RemoteEndpoint for DatagramRemoteEndpoint<US>[src]

type SocketAddr = US::SocketAddr

type InboundContext = DatagramInboundContext<Self::SocketAddr>

Loading content...