[]Struct rocket::http::uri::Segments

pub struct Segments<'a>(pub &'a str);

Iterator over the segments of an absolute URI path. Skips empty segments.


use rocket::http::uri::Origin;

let uri = Origin::parse("/a/////b/c////////d").unwrap();
let segments = uri.segments();
for (i, segment) in segments.enumerate() {
    match i {
        0 => assert_eq!(segment, "a"),
        1 => assert_eq!(segment, "b"),
        2 => assert_eq!(segment, "c"),
        3 => assert_eq!(segment, "d"),
        _ => panic!("only four segments")


impl<'a> Segments<'a>

pub fn into_path_buf(
    allow_dotfiles: bool
) -> Result<PathBuf, SegmentError>

Creates a PathBuf from a Segments iterator. The returned PathBuf is percent-decoded. If a segment is equal to "..", the previous segment (if any) is skipped.

For security purposes, if a segment meets any of the following conditions, an Err is returned indicating the condition met:

  • Decoded segment starts with any of: '*'
  • Decoded segment ends with any of: :, >, <
  • Decoded segment contains any of: /
  • On Windows, decoded segment contains any of: \
  • Percent-encoding results in invalid UTF8.

Additionally, if allow_dotfiles is false, an Err is returned if the following condition is met:

  • Decoded segment starts with any of: . (except ..)

As a result of these conditions, a PathBuf derived via FromSegments is safe to interpolate within, or use as a suffix of, a path without additional checks.

Trait Implementations

impl<'a> Clone for Segments<'a>

impl<'a> Debug for Segments<'a>

impl<'a> FromSegments<'a> for Segments<'a>[src]

type Error = !

The associated error to be returned when parsing fails.

impl<'a> Iterator for Segments<'a>

type Item = &'a str

The type of the elements being iterated over.

Auto Trait Implementations

impl<'a> RefUnwindSafe for Segments<'a>

impl<'a> Send for Segments<'a>

impl<'a> Sync for Segments<'a>

impl<'a> Unpin for Segments<'a>

impl<'a> UnwindSafe for Segments<'a>

Blanket Implementations

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

impl<T, I> AsResult<T, I> for T where
    I: Input, 

impl<T> Borrow<T> for T where
    T: ?Sized

impl<T> BorrowMut<T> for T where
    T: ?Sized

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

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

impl<T> IntoCollection<T> for T

impl<I> IntoIterator for I where
    I: Iterator

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<I> IteratorRandom for I where
    I: Iterator

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.

impl<T> Typeable for T where
    T: Any

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,