pub struct FilePath<'a>(/* private fields */);Expand description
A SchemeType::File path.
Implementations§
Source§impl FilePath<'_>
impl FilePath<'_>
Sourcepub fn iter_strs(&self) -> SplitSlashes<'_> ⓘ
pub fn iter_strs(&self) -> SplitSlashes<'_> ⓘ
The segments as strs.
Sourcepub fn range_str<B: RangeBounds<isize>>(&self, range: B) -> Option<&str>
pub fn range_str<B: RangeBounds<isize>>(&self, range: B) -> Option<&str>
The range of segments as a str.
Sourcepub fn iter(&self) -> FilePathSegmentsIter<'_> ⓘ
pub fn iter(&self) -> FilePathSegmentsIter<'_> ⓘ
The FilePathSegmentsIter.
Sourcepub fn get(&self, index: isize) -> Option<FilePathSegment<'_>>
pub fn get(&self, index: isize) -> Option<FilePathSegment<'_>>
The indexth FilePathSegment.
Sourcepub fn range<B: RangeBounds<isize>>(
&self,
range: B,
) -> Option<FilePathSegments<'_>>
pub fn range<B: RangeBounds<isize>>( &self, range: B, ) -> Option<FilePathSegments<'_>>
The range of FilePathSegments.
§Examples
use better_url::prelude::*;
let path = FilePath::new("/ab/cd/ef");
assert_eq!(path.range(0.. 2).unwrap(), "ab/cd");
assert_eq!(path.range(0.. -1).unwrap(), "ab/cd");
assert_eq!(path.range(0..= 2).unwrap(), "ab/cd/ef");
assert_eq!(path.range(0..=-1).unwrap(), "ab/cd/ef");Source§impl FilePath<'_>
impl FilePath<'_>
Sourcepub fn push<'a, T: Into<FilePathSegment<'a>>>(&mut self, value: T) -> bool
pub fn push<'a, T: Into<FilePathSegment<'a>>>(&mut self, value: T) -> bool
Append value.
§Examples
use better_url::prelude::*;
let mut path = FilePath::new("/abc/def/ghi");
path.push("123"); assert_eq!(path, "/abc/def/ghi/123");
path.push(".." ); assert_eq!(path, "/abc/def/ghi/" );
path.push(".." ); assert_eq!(path, "/abc/def/ghi/" );
path.push("." ); assert_eq!(path, "/abc/def/ghi//" );Sourcepub fn prepend<'a, T: Into<FilePathSegment<'a>>>(&mut self, value: T) -> bool
pub fn prepend<'a, T: Into<FilePathSegment<'a>>>(&mut self, value: T) -> bool
Prepend value.
§Examples
use better_url::prelude::*;
let mut path = FilePath::new("/abc/def/ghi");
path.prepend("123"); assert_eq!(path, "/123/abc/def/ghi");
path.prepend("." ); assert_eq!(path, "/123/abc/def/ghi");
path.prepend(".." ); assert_eq!(path, "/123/abc/def/ghi");Sourcepub fn set<'a, T: Into<FilePathSegment<'a>>>(
&mut self,
index: isize,
value: Option<T>,
) -> Result<bool, SetPathError>
pub fn set<'a, T: Into<FilePathSegment<'a>>>( &mut self, index: isize, value: Option<T>, ) -> Result<bool, SetPathError>
Set, insert, or remove the indexth segment.
If value is None and index is out of bounds, does nothing.
§Errors
If value is Some and index is more than 1 out of bounds, returns the error InsertNotFound.
If value is None and index is the only segment, returns the error CantBeEmpty.
§Examples
use better_url::prelude::*;
let mut path = FilePath::new("/c:/abc/def/ghi");
path.set( 1, Some(".." )).unwrap(); assert_eq!(path, "/c:/def/ghi" );
path.set( 0, Some("e|" )).unwrap(); assert_eq!(path, "/e:/def/ghi" );
path.set(-4, Some("123")).unwrap(); assert_eq!(path, "/123/e:/def/ghi");
path.set( 2, Some(".." )).unwrap(); assert_eq!(path, "/123/ghi" );
path.set( 2, Some("456")).unwrap(); assert_eq!(path, "/123/ghi/456" );Sourcepub fn set_range<'a, T: Into<FilePathSegments<'a>>, B: RangeBounds<isize>>(
&mut self,
range: B,
value: Option<T>,
) -> Result<bool, SetPathError>
pub fn set_range<'a, T: Into<FilePathSegments<'a>>, B: RangeBounds<isize>>( &mut self, range: B, value: Option<T>, ) -> Result<bool, SetPathError>
Set the range of segments.
§Errors
If Self::range_str returns None, returns the error RangeNotFound.
If value is None and range contains all segments, returns the error CantBeEmpty.
§Examples
use better_url::prelude::*;
let mut path = FilePath::new("/c:/abc/def/ghi");
path.set_range(1..2, Some(".././123/.")).unwrap(); assert_eq!(path, "/c:/123/def/ghi");Sourcepub fn insert<'a, T: Into<FilePathSegment<'a>>>(
&mut self,
index: isize,
value: T,
) -> Result<bool, SetPathError>
pub fn insert<'a, T: Into<FilePathSegment<'a>>>( &mut self, index: isize, value: T, ) -> Result<bool, SetPathError>
Insert a new indexth segment.
§Errors
If the insert isn’t found, returns the error InsertNotFound.
§Examples
use better_url::prelude::*;
let mut path = FilePath::new("/c:/abc/def/ghi");
path.insert( 2, "123").unwrap(); assert_eq!(path, "/c:/abc/123/def/ghi");
path.insert( 3, ".." ).unwrap(); assert_eq!(path, "/c:/abc/def/ghi" );
path.insert(-1, "123").unwrap(); assert_eq!(path, "/c:/abc/def/ghi/123");Source§impl FilePath<'_>
impl FilePath<'_>
Sourcepub fn pop(&mut self) -> Result<bool, SetPathError>
pub fn pop(&mut self) -> Result<bool, SetPathError>
Remove the last segment if it exists.
§Errors
If there’s only one segment, returns the error CantBeEmpty.
Sourcepub fn pop_if_empty(&mut self) -> Result<bool, SetPathError>
pub fn pop_if_empty(&mut self) -> Result<bool, SetPathError>
Remove the last segment if it exists and is empty.
§Errors
If there is only one segment and it’s empty, returns the error CantBeNone.
Sourcepub fn remove(&mut self, index: isize) -> Result<bool, SetPathError>
pub fn remove(&mut self, index: isize) -> Result<bool, SetPathError>
Remove the indexth segment if it exists.
§Errors
If there is only one segment, returns the error CantBeEmpty.
Source§impl<'a> FilePath<'a>
impl<'a> FilePath<'a>
Sourcepub unsafe fn new_unchecked<T: Into<Cow<'a, str>>>(value: T) -> Self
pub unsafe fn new_unchecked<T: Into<Cow<'a, str>>>(value: T) -> Self
Sourcepub fn segments(&self) -> FilePathSegments<'_>
pub fn segments(&self) -> FilePathSegments<'_>
The FilePathSegments.
Sourcepub fn into_inner(self) -> Cow<'a, str>
pub fn into_inner(self) -> Cow<'a, str>
Turn into the inner Cow.
Sourcepub fn into_owned(self) -> FilePath<'static>
pub fn into_owned(self) -> FilePath<'static>
Turn into an owned Self.