[][src]Struct uriparse::path::Segment

pub struct Segment<'segment> { /* fields omitted */ }

A segment of a path.

Segments are separated from other segments with the '/' delimiter.

Implementations

impl<'_> Segment<'_>[src]

pub fn as_borrowed(&self) -> Segment<'_>[src]

Returns a new segment which is identical but has as lifetime tied to this segment.

pub fn as_str(&self) -> &str[src]

Returns a str representation of the segment.

Examples

use std::convert::TryFrom;

use uriparse::Segment;

let segment = Segment::try_from("segment").unwrap();
assert_eq!(segment.as_str(), "segment");

pub fn empty() -> Segment<'static>[src]

Constructs a segment that is empty.

Examples

use uriparse::Segment;

assert_eq!(Segment::empty(),  "");

pub fn into_owned(self) -> Segment<'static>[src]

Converts the Segment into an owned copy.

If you construct the segment from a source with a non-static lifetime, you may run into lifetime problems due to the way the struct is designed. Calling this function will ensure that the returned value has a static lifetime.

This is different from just cloning. Cloning the segment will just copy the references, and thus the lifetime will remain the same.

pub fn is_dot_segment(&self) -> bool[src]

Returns whether the segment is a dot segment, i.e., is "." or "..".

Examples

use std::convert::TryFrom;

use uriparse::Segment;

let segment = Segment::try_from("segment").unwrap();
assert!(!segment.is_dot_segment());

let segment = Segment::try_from(".").unwrap();
assert!(segment.is_dot_segment());

let segment = Segment::try_from("..").unwrap();
assert!(segment.is_dot_segment());

pub fn is_double_dot_segment(&self) -> bool[src]

Returns whether the segment is a dot segment, i.e., is "..".

Examples

use std::convert::TryFrom;

use uriparse::Segment;

let segment = Segment::try_from("segment").unwrap();
assert!(!segment.is_double_dot_segment());

let segment = Segment::try_from(".").unwrap();
assert!(!segment.is_double_dot_segment());

let segment = Segment::try_from("..").unwrap();
assert!(segment.is_double_dot_segment());

pub fn is_normalized(&self) -> bool[src]

Returns whether the segment is normalized.

A normalized segment will have no bytes that are in the unreserved character set percent-encoded and all alphabetical characters in percent-encodings will be uppercase.

Examples

use std::convert::TryFrom;

use uriparse::Segment;

let segment = Segment::try_from("segment").unwrap();
assert!(segment.is_normalized());

let mut segment = Segment::try_from("%ff%ff").unwrap();
assert!(!segment.is_normalized());
segment.normalize();
assert!(segment.is_normalized());

pub fn is_single_dot_segment(&self) -> bool[src]

Returns whether the segment is a dot segment, i.e., is ".".

Examples

use std::convert::TryFrom;

use uriparse::Segment;

let segment = Segment::try_from("segment").unwrap();
assert!(!segment.is_single_dot_segment());

let segment = Segment::try_from(".").unwrap();
assert!(segment.is_single_dot_segment());

let segment = Segment::try_from("..").unwrap();
assert!(!segment.is_single_dot_segment());

pub fn normalize(&mut self)[src]

Normalizes the segment such that it will have no bytes that are in the unreserved character set percent-encoded and all alphabetical characters in percent-encodings will be uppercase.

If the segment is already normalized, the function will return immediately. Otherwise, if the segment is not owned, this function will perform an allocation to clone it. The normalization itself though, is done in-place with no extra memory allocations required.

Examples

use std::convert::TryFrom;

use uriparse::Segment;

let mut segment = Segment::try_from("segment").unwrap();
segment.normalize();
assert_eq!(segment, "segment");

let mut segment = Segment::try_from("%ff%41").unwrap();
assert_eq!(segment, "%ff%41");
segment.normalize();
assert_eq!(segment, "%FFA");

Trait Implementations

impl<'_> AsRef<[u8]> for Segment<'_>[src]

impl<'_> AsRef<str> for Segment<'_>[src]

impl<'segment> Clone for Segment<'segment>[src]

impl<'segment> Debug for Segment<'segment>[src]

impl<'_> Deref for Segment<'_>[src]

type Target = str

The resulting type after dereferencing.

impl<'_> Display for Segment<'_>[src]

impl<'_> Eq for Segment<'_>[src]

impl<'segment> From<Segment<'segment>> for String[src]

impl<'_> Hash for Segment<'_>[src]

impl<'a, '_> PartialEq<&'a [u8]> for Segment<'_>[src]

impl<'a, '_> PartialEq<&'a str> for Segment<'_>[src]

impl<'_> PartialEq<[u8]> for Segment<'_>[src]

impl<'_> PartialEq<Segment<'_>> for Segment<'_>[src]

impl<'segment> PartialEq<Segment<'segment>> for [u8][src]

impl<'a, 'segment> PartialEq<Segment<'segment>> for &'a [u8][src]

impl<'segment> PartialEq<Segment<'segment>> for str[src]

impl<'a, 'segment> PartialEq<Segment<'segment>> for &'a str[src]

impl<'_> PartialEq<str> for Segment<'_>[src]

impl<'segment> TryFrom<&'segment [u8]> for Segment<'segment>[src]

type Error = PathError

The type returned in the event of a conversion error.

impl<'segment> TryFrom<&'segment str> for Segment<'segment>[src]

type Error = PathError

The type returned in the event of a conversion error.

Auto Trait Implementations

impl<'segment> RefUnwindSafe for Segment<'segment>

impl<'segment> Send for Segment<'segment>

impl<'segment> Sync for Segment<'segment>

impl<'segment> Unpin for Segment<'segment>

impl<'segment> UnwindSafe for Segment<'segment>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.