pub struct Path(/* private fields */);Expand description
Percent-encoded URL path.
Implementations§
Source§impl Path
impl Path
Sourcepub fn new(src: &str) -> Result<&Path, InvalidUrl>
pub fn new(src: &str) -> Result<&Path, InvalidUrl>
Strictly validates a path: *( pchar / "/" ).
Sourcepub fn from_static(src: &'static str) -> &'static Path
pub fn from_static(src: &'static str) -> &'static Path
Sourcepub fn is_absolute(&self) -> bool
pub fn is_absolute(&self) -> bool
Returns true if the path starts with /.
Sourcepub fn decode(&self) -> Cow<'_, str>
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");Sourcepub fn decode_safe(&self) -> Cow<'_, str>
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");Sourcepub fn segments(&self) -> Segments<'_> ⓘ
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);Sourcepub fn file_name(&self) -> Option<&str>
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);Sourcepub fn file_stem(&self) -> Option<&str>
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"));Sourcepub fn extension(&self) -> Option<&str>
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);Sourcepub fn extensions(&self) -> Option<&str>
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);