Struct uriparse::path::Path[][src]

pub struct Path<'path> { /* fields omitted */ }

The path component as defined in [RFC3986, Section 3.3].

A path is composed of a sequence of segments. It is also either absolute or relative, where an absolute path starts with a '/'. A URI with an authority always has an absolute path regardless of whether or not the path was empty (i.e. "http://example.com" has a single empty path segment and is absolute).

Methods

impl<'path> Path<'path>
[src]

Clears all segments from the path leaving a single empty segment.

Examples

use std::convert::TryFrom;

use uriparse::Path;

let mut path = Path::try_from("/my/path").unwrap();
assert_eq!(path, "/my/path");
path.clear();
assert_eq!(path, "/");

Converts the Path into an owned copy.

If you construct the path 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 path will just copy the references, and thus the lifetime will remain the same.

Returns whether or not the path is absolute (i.e. it starts with a '/').

Any path following an [Authority] will always be parsed to be absolute.

Examples

use std::convert::TryFrom;

use uriparse::Path;

let path = Path::try_from("/my/path").unwrap();
assert_eq!(path.is_absolute(), true);

Pops the last segment off of the path.

If the path only contains one segment, then that segment will become empty.

use std::convert::TryFrom;

use uriparse::Path;

let mut path = Path::try_from("/my/path").unwrap();
path.pop();
assert_eq!(path, "/my");
path.pop();
assert_eq!(path, "/");

Pushes a segment onto the path.

If the conversion to a Segment fails, an InvalidPath will be returned.

use std::convert::TryFrom;

use uriparse::Path;

let mut path = Path::try_from("/my/path").unwrap();
path.push("test");
assert_eq!(path, "/my/path/test");

Important traits for &'a [u8]

Returns the segments of the path.

If you require mutability, use Path::segments_mut.

Examples

use std::convert::TryFrom;

use uriparse::Path;

let mut path = Path::try_from("/my/path").unwrap();
assert_eq!(path.segments()[1], "path");

Important traits for &'a [u8]

Returns the segments of the path mutably.

Due to the required restriction that there must be at least one segment in a path, this mutability only applies to the segments themselves, not the container.

Examples

use std::convert::TryFrom;

use uriparse::{Path, Segment};

let mut path = Path::try_from("/my/path").unwrap();

// TODO: Remove this block once NLL is stable.
{
    let mut segments = path.segments_mut();
    segments[1] = Segment::try_from("test").unwrap();
}

assert_eq!(path, "/my/test");

Sets whether or not the path is absolute (i.e. it starts with a '/').

Examples

use std::convert::TryFrom;

use uriparse::Path;

let mut path = Path::try_from("/my/path").unwrap();
path.set_absolute(false);
assert_eq!(path, "my/path");

Trait Implementations

impl<'path> Clone for Path<'path>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<'path> Debug for Path<'path>
[src]

Formats the value using the given formatter. Read more

impl<'path> Eq for Path<'path>
[src]

impl<'path> Hash for Path<'path>
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

impl<'path> PartialEq for Path<'path>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'path> Display for Path<'path>
[src]

Formats the value using the given formatter. Read more

impl<'path> From<Path<'path>> for String
[src]

Performs the conversion.

impl<'path> PartialEq<[u8]> for Path<'path>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'path> PartialEq<Path<'path>> for [u8]
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'path> PartialEq<&'a [u8]> for Path<'path>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'path> PartialEq<Path<'path>> for &'a [u8]
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'path> PartialEq<str> for Path<'path>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'path> PartialEq<Path<'path>> for str
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'path> PartialEq<&'a str> for Path<'path>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a, 'path> PartialEq<Path<'path>> for &'a str
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'path> TryFrom<&'path [u8]> for Path<'path>
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<'path> TryFrom<&'path str> for Path<'path>
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

Auto Trait Implementations

impl<'path> Send for Path<'path>

impl<'path> Sync for Path<'path>