Struct fluent_uri::View

source ·
pub struct View<'a, T: ?Sized + Lens>(_, _);
Expand description

A smart pointer that allows viewing a mutable byte slice as &T.

This struct was introduced considering the fact that a bare &mut EStr wouldn’t do for in-place decoding because such decoding breaks the invariants of EStr.

Six types of lenses may be used as T: EStr, str, Scheme, Authority, Host, and Path.

Implementations§

source§

impl<'a> View<'a, EStr>

An EStr view into a mutable byte slice that allows in-place percent-decoding.

source

pub fn decode_in_place(self) -> DecodeInPlace<'a>

Decodes the View<EStr> in-place.

source

pub fn split_view(self, delim: char) -> SplitView<'a>

Returns an iterator over subslices of the View<EStr> separated by the given delimiter.

Panics

Panics if the delimiter is not a reserved character.

source

pub fn split_once_view(self, delim: char) -> Result<(Self, Self), Self>

Splits the View<EStr> on the first occurrence of the given delimiter and returns prefix before delimiter and suffix after delimiter.

Returns Err(self) if the delimiter is not found.

Panics

Panics if the delimiter is not a reserved character.

source§

impl<'a, T: ?Sized + Lens<Target = [u8]>> View<'a, T>

These methods are only available for lenses EStr, str, Scheme, and Path.

source

pub fn into_ref(self) -> &'a T

Consumes this View and yields the underlying &T.

source

pub fn into_bytes(self) -> &'a mut [u8]

Consumes this View and yields the underlying mutable byte slice.

source§

impl<'a> View<'a, Scheme>

A Scheme view into a mutable byte slice that allows lowercasing in-place.

source

pub fn make_lowercase(&mut self)

Converts the scheme to lower case in-place.

This method is slightly faster than slice::make_ascii_lowercase.

Examples
use fluent_uri::Uri;

let mut bytes = *b"HTTP://example.com/";
let mut uri = Uri::parse_mut(&mut bytes)?;

let mut scheme = uri.take_scheme().unwrap();
scheme.make_lowercase();
assert_eq!(scheme.as_str(), "http");
source§

impl<'i, 'a> View<'i, Authority<&'a mut [u8]>>

An Authority view into a mutable byte slice.

source

pub fn into_str_view(self) -> View<'a, str>

Consumes this View<Authority> and yields the underlying View<str>.

The userinfo or port subcomponent is truncated if it is already taken.

Panics

Panics if the host subcomponent is already taken.

source

pub fn take_userinfo(&mut self) -> Option<View<'a, EStr>>

Takes a view of the userinfo subcomponent, leaving a None in its place.

source

pub fn take_host(&mut self) -> View<'_, Host<&'a mut [u8]>>

Takes a view of the host subcomponent.

Panics

Panics if the host subcomponent is already taken.

source

pub fn take_port(&mut self) -> Option<View<'a, str>>

Takes a view of the port subcomponent, leaving a None in its place.

source§

impl<'i, 'a> View<'i, Host<&'a mut [u8]>>

A Host view into a mutable byte slice.

source

pub fn into_str_view(self) -> View<'a, str>

Consumes this View<Host> and yields the underlying View<str>.

source

pub fn unwrap_reg_name(self) -> View<'a, EStr>

Consumes this View<Host> and yields the underlying View<EStr>, assuming that the host is a registered name.

Panics

Panics if the host is not a registered name.

source§

impl<'a> View<'a, Path>

A Path view into a mutable byte slice.

source

pub fn into_estr_view(self) -> View<'a, EStr>

Consumes this View<Path> and yields the underlying View<EStr>.

source

pub fn segments_view(self) -> SplitView<'a>

Returns an iterator over the views of path segments.

Trait Implementations§

source§

impl<'a, T: ?Sized + Lens> AsRef<T> for View<'a, T>

source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'a, T: ?Sized + Debug + Lens> Debug for View<'a, T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a, T: ?Sized + Lens> Deref for View<'a, T>

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &T

Dereferences the value.
source§

impl<'a, T: ?Sized + Display + Lens> Display for View<'a, T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, T: ?Sized> RefUnwindSafe for View<'a, T>where T: RefUnwindSafe, <T as Lens>::Target: RefUnwindSafe,

§

impl<'a, T: ?Sized> Send for View<'a, T>where T: Sync, <T as Lens>::Target: Send,

§

impl<'a, T: ?Sized> Sync for View<'a, T>where T: Sync, <T as Lens>::Target: Sync,

§

impl<'a, T: ?Sized> Unpin for View<'a, T>

§

impl<'a, T> !UnwindSafe for View<'a, T>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.