Trait AnyUriRef

Source
pub trait AnyUriRef {
    // Required method
    fn components(&self) -> UriRawComponents<'_>;

    // Provided methods
    fn write_to<T: Write + ?Sized>(&self, write: &mut T) -> Result<(), Error> { ... }
    fn display(&self) -> UriDisplay<'_, Self> { ... }
    fn is_empty(&self) -> bool { ... }
    fn uri_type(&self) -> UriType { ... }
    fn to_uri_ref_buf(&self) -> UriRefBuf { ... }
    fn write_resolved<T: Write + ?Sized, D: AnyUriRef + ?Sized>(
        &self,
        target: &D,
        f: &mut T,
    ) -> Result<(), ResolveError> { ... }
    fn resolved<T: AnyUriRef + ?Sized>(
        &self,
        dest: &T,
    ) -> Result<UriRefBuf, ResolveError> { ... }
}
Expand description

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

Required Methods§

Source

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.

Provided Methods§

Source

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.

Source

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

fn is_empty(&self) -> bool

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

Source

fn uri_type(&self) -> UriType

Gets the UriType of the underlying URI-reference.

Source

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.

Source

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.

Source

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.

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.

Implementations on Foreign Types§

Source§

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

Blanket implementation for Copy-On-Write types.

Source§

fn components(&self) -> UriRawComponents<'_>

Source§

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

Source§

fn is_empty(&self) -> bool

Source§

fn uri_type(&self) -> UriType

Source§

fn to_uri_ref_buf(&self) -> UriRefBuf

Source§

fn write_resolved<W: Write + ?Sized, D: AnyUriRef + ?Sized>( &self, dest: &D, output: &mut W, ) -> Result<(), ResolveError>

Source§

fn resolved<W: AnyUriRef + ?Sized>( &self, dest: &W, ) -> Result<UriRefBuf, ResolveError>

Implementors§