[][src]Trait async_coap_uri::AnyUriRef

pub trait AnyUriRef {
#[must_use]
    fn components(&self) -> UriRawComponents;

    fn write_to<T: Write + ?Sized>(&self, write: &mut T) -> Result<(), Error> { ... }
#[must_use] fn display(&self) -> UriDisplay<Self> { ... }
#[must_use] fn is_empty(&self) -> bool { ... }
#[must_use] fn uri_type(&self) -> UriType { ... }
#[must_use] fn to_uri_ref_buf(&self) -> UriRefBuf { ... }
fn write_resolved<T: Write + ?Sized, D: AnyUriRef + ?Sized>(
        &self,
        target: &D,
        f: &mut T
    ) -> Result<(), ResolveError> { ... }
#[must_use] fn resolved<T: AnyUriRef + ?Sized>(
        &self,
        dest: &T
    ) -> Result<UriRefBuf, ResolveError> { ... } }

Trait for objects that represent logical URI-references. Useful for generic programming.

Required methods

#[must_use] fn components(&self) -> UriRawComponents

Returns a UriRawComponents instance which contains all of the components for this URI reference.

This is the only method that is required to be implemented---all other methods have defaults in place which use this method, but they may be inefficient.

Loading content...

Provided methods

fn write_to<T: Write + ?Sized>(&self, write: &mut T) -> Result<(), Error>

Serializes this URI to anything implementing core::fmt::Write. Override with care!

The purpose of this method is to provide a uniform way for a type that implements this trait to write out a well-formed URI; without making any assumptions on what that type might write out for std::fmt::Display (or even if it implements it at all). Thus, traits can be a bit more fast-and-loose with their implementations of std::fmt::Display.

See the documentation for display and UriDisplay for examples of usage.

Safety

Calling this method is not unsafe, but implementing it is! The underlying guarantee is that the written URI reference SHALL be well-formed. If this method writes out something that is not a valid URI reference, the resulting behavior is undefined.

TODO: Investigate implications of making this method unsafe.

#[must_use] fn display(&self) -> UriDisplay<Self>

Wraps this AnyUriRef instance in a UriDisplay object for use with formatting macros like write! and format!.

The resulting instance will use the AnyUriRef::write_to method on this trait.

This method should not be overridden: override AnyUriRef::write_to instead.

This method is similar to the display method on std::path::Path.

Example

use async_coap_uri::prelude::*;

let uri_ref = uri_ref!("http://example.com/");

println!("uri_ref = {}", uri_ref.display());

#[must_use] fn is_empty(&self) -> bool

Returns true if the underlying URI-reference is actually the empty reference.

#[must_use] fn uri_type(&self) -> UriType

Gets the UriType of the underlying URI-reference.

#[must_use] fn to_uri_ref_buf(&self) -> UriRefBuf

Creates a new UriRefBuf from this AnyUriRef.

The default implementation uses the AnyUriRef::write_to method to render out the content of the URI-reference.

fn write_resolved<T: Write + ?Sized, D: AnyUriRef + ?Sized>(
    &self,
    target: &D,
    f: &mut T
) -> Result<(), ResolveError>

Writes out to a core::fmt::Write instance the result of performing URI resolution against target, with self being the base URI.

#[must_use] fn resolved<T: AnyUriRef + ?Sized>(
    &self,
    dest: &T
) -> Result<UriRefBuf, ResolveError>

Creates a new UriRefBuf that contains the result of performing URI resolution with dest.

Loading content...

Implementations on Foreign Types

impl<'a, T: AnyUriRef + Clone + ?Sized> AnyUriRef for Cow<'a, T>[src]

Blanket implementation for Copy-On-Write types.

Loading content...

Implementors

impl AnyUriRef for RelRef[src]

fn uri_type(&self) -> UriType[src]

Determines what kind of relative reference this is:

This function may return any one of the following values:

fn components(&self) -> UriRawComponents[src]

Breaks down this relative reference into its raw components.

impl AnyUriRef for RelRefBuf[src]

impl AnyUriRef for Uri[src]

fn uri_type(&self) -> UriType[src]

Determines what kind of URI this is.

This function may return any one of the following values:

impl AnyUriRef for UriBuf[src]

impl AnyUriRef for UriRef[src]

impl AnyUriRef for UriRefBuf[src]

impl<'_> AnyUriRef for UriRawComponents<'_>[src]

fn write_to<T: Write + ?Sized>(&self, f: &mut T) -> Result<(), Error>[src]

Note that the implementation of this method for UriRawComponents ignores the value of self.userinfo, self.host, and self.port; instead relying entirely on self.authority.

Loading content...