Trait rocket::request::FromSegments[][src]

pub trait FromSegments<'r>: Sized {
    type Error: Debug;
    fn from_segments(segments: Segments<'r, Path>) -> Result<Self, Self::Error>;
}
Expand description

Trait to convert many dynamic path segment strings to a concrete value.

This is the .. analog to FromParam, and its functionality is identical to it with one exception: this trait applies to segment parameters of the form <param..>, where param is of some type T that implements FromSegments. T::from_segments is called to convert the matched segments (via the Segments iterator) into the implementing type.

Provided Implementations

PathBuf

The PathBuf implementation constructs a path from the segments iterator. Each segment is percent-decoded. If a segment equals “..” before or after decoding, the previous segment (if any) is omitted. For security purposes, any other segments that begin with “*” or “.” are ignored. If a percent-decoded segment results in invalid UTF8, an Err is returned with the Utf8Error.

Associated Types

type Error: Debug[src]

The associated error to be returned when parsing fails.

Required methods

fn from_segments(segments: Segments<'r, Path>) -> Result<Self, Self::Error>[src]

Parses an instance of Self from many dynamic path parameter strings or returns an Error if one cannot be parsed.

Implementations on Foreign Types

impl FromSegments<'_> for PathBuf[src]

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: . (except ..), *
  • Decoded segment ends with any of: :, >, <
  • Decoded segment contains any of: /
  • On Windows, decoded segment contains any of: \
  • Percent-encoding results in invalid UTF8.

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.

type Error = PathError

fn from_segments(segments: Segments<'_, Path>) -> Result<Self, Self::Error>[src]

impl<'r, T: FromSegments<'r>> FromSegments<'r> for Result<T, T::Error>[src]

type Error = Infallible

fn from_segments(
    segments: Segments<'r, Path>
) -> Result<Result<T, T::Error>, Self::Error>
[src]

impl<'r, T: FromSegments<'r>> FromSegments<'r> for Option<T>[src]

type Error = Infallible

fn from_segments(segments: Segments<'r, Path>) -> Result<Option<T>, Self::Error>[src]

Implementors

impl<'r> FromSegments<'r> for Segments<'r, Path>[src]

type Error = Infallible

fn from_segments(segments: Self) -> Result<Self, Self::Error>[src]