Skip to main content

Path

Struct Path 

Source
pub struct Path(/* private fields */);
Expand description

Percent-encoded URL path.

Implementations§

Source§

impl Path

Source

pub const fn as_str(&self) -> &str

Returns the component as a string slice.

Source§

impl Path

Source

pub fn new(src: &str) -> Result<&Path, InvalidUrl>

Strictly validates a path: *( pchar / "/" ).

Source

pub fn from_static(src: &'static str) -> &'static Path

Converts a static string to a path.

§Panics

Panics if the path is not valid.

Source

pub fn is_empty(&self) -> bool

Returns true if the path is empty.

Source

pub fn is_absolute(&self) -> bool

Returns true if the path starts with /.

Source

pub fn decode(&self) -> Cow<'_, str>

Returns the decoded path.

use urly::Path;

assert_eq!(Path::from_static("/a%20b/c%2Fd").decode(), "/a b/c/d");
Source

pub fn decode_safe(&self) -> Cow<'_, str>

Returns the decoded path, keeping %2F and %25 encoded, so the result can still be split into segments.

use urly::Path;

assert_eq!(Path::from_static("/a%20b/c%2Fd").decode_safe(), "/a b/c%2Fd");
Source

pub fn segments(&self) -> Segments<'_> ⓘ

Returns an iterator over the percent-encoded segments.

use urly::Path;

let segments: Vec<_> = Path::from_static("/a/b%20c/").segments().collect();
assert_eq!(segments, ["a", "b%20c", ""]);
assert_eq!(Path::from_static("").segments().count(), 0);
Source

pub fn file_name(&self) -> Option<&str>

Returns the last segment, unless it is empty, . or ...

use urly::Path;

assert_eq!(Path::from_static("/a/file.tar.gz").file_name(), Some("file.tar.gz"));
assert_eq!(Path::from_static("/a/").file_name(), None);
Source

pub fn file_stem(&self) -> Option<&str>

Returns the file name without its last extension.

use urly::Path;

assert_eq!(Path::from_static("/file.tar.gz").file_stem(), Some("file.tar"));
assert_eq!(Path::from_static("/.hidden").file_stem(), Some(".hidden"));
Source

pub fn extension(&self) -> Option<&str>

Returns the last extension of the file name, without the dot.

use urly::Path;

assert_eq!(Path::from_static("/file.tar.gz").extension(), Some("gz"));
assert_eq!(Path::from_static("/.hidden").extension(), None);
Source

pub fn extensions(&self) -> Option<&str>

Returns all extensions of the file name, without the leading dot.

use urly::Path;

assert_eq!(Path::from_static("/file.tar.gz").extensions(), Some("tar.gz"));
assert_eq!(Path::from_static("/file").extensions(), None);

Trait Implementations§

Source§

impl AsRef<str> for Path

Source§

fn as_ref(&self) -> &str

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

impl Debug for Path

Source§

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

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

impl Display for Path

Source§

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

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

impl Eq for Path

Source§

impl Hash for Path

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
Source§

impl Ord for Path

Source§

fn cmp(&self, other: &Path) -> Ordering

This method returns an Ordering between self and other. Read more
Source§

impl PartialEq for Path

Source§

fn eq(&self, other: &Path) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<&str> for Path

Source§

fn eq(&self, other: &&str) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<Path> for str

Source§

fn eq(&self, other: &Path) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<Path> for &str

Source§

fn eq(&self, other: &Path) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<str> for Path

Source§

fn eq(&self, other: &str) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for Path

Source§

fn partial_cmp(&self, other: &Path) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a> TryFrom<&'a str> for &'a Path

Source§

type Error = InvalidUrl

The type returned in the event of a conversion error.
Source§

fn try_from(s: &'a str) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl !Sized for Path

§

impl Freeze for Path

§

impl RefUnwindSafe for Path

§

impl Send for Path

§

impl Sync for Path

§

impl Unpin for Path

§

impl UnsafeUnpin for Path

§

impl UnwindSafe for Path

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more