pub trait AnyUriRef {
// Required method
fn components(&self) -> UriRawComponents<'_>;
// Provided methods
fn write_to<T>(&self, write: &mut T) -> Result<(), Error>
where T: Write + ?Sized { ... }
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, D>(
&self,
target: &D,
f: &mut T,
) -> Result<(), ResolveError>
where T: Write + ?Sized,
D: AnyUriRef + ?Sized { ... }
fn resolved<T>(&self, dest: &T) -> Result<UriRefBuf, ResolveError>
where T: AnyUriRef + ?Sized { ... }
}Expand description
Trait for objects that represent logical URI-references. Useful for generic programming.
Required Methods§
Sourcefn components(&self) -> UriRawComponents<'_>
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§
Sourcefn write_to<T>(&self, write: &mut T) -> Result<(), Error>
fn write_to<T>(&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.
Sourcefn display(&self) -> UriDisplay<'_, Self>
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());Sourcefn is_empty(&self) -> bool
fn is_empty(&self) -> bool
Returns true if the underlying URI-reference is actually the empty reference.
Sourcefn to_uri_ref_buf(&self) -> UriRefBuf
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.
Sourcefn write_resolved<T, D>(
&self,
target: &D,
f: &mut T,
) -> Result<(), ResolveError>
fn write_resolved<T, D>( &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.
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 for Cow<'a, T>
Blanket implementation for Copy-On-Write types.
impl<'a, T> AnyUriRef for Cow<'a, T>
Blanket implementation for Copy-On-Write types.