pub struct PathStyle { /* private fields */ }Expand description
The rules of a source’s paths: which characters separate the parts, how a root looks, whether names differ by case, and which names are hidden.
posix is /-separated with one root, case-sensitive,
with dot names hidden. windows has drive roots such
as C:\ and share roots such as \\server\share\, accepts both / and
\ when a path is typed or pasted, writes \, ignores case, and hides
nothing by name. host is the style of the machine the
application runs on, the default of a source.
use gpui_cn::PathStyle;
let windows = PathStyle::windows();
let path = windows.path("c:/Users\\me/");
assert_eq!(path.as_str(), "c:\\Users\\me");
assert_eq!(path, windows.path("C:\\users\\ME"));
assert_eq!(windows.path("C:\\").parent(), None);Implementations§
Source§impl PathStyle
impl PathStyle
Sourcepub fn windows() -> Self
pub fn windows() -> Self
Drive and share roots, \ as the written separator, with /
accepted too, and names that ignore case.
Sourcepub fn with_display_separator(self, separator: char) -> Self
pub fn with_display_separator(self, separator: char) -> Self
Writes / instead of \ in a Windows-style path. A POSIX style
always writes /.
Sourcepub fn with_case_sensitive(self, case_sensitive: bool) -> Self
pub fn with_case_sensitive(self, case_sensitive: bool) -> Self
Sets whether two names that differ only by case are different names.
Sourcepub fn with_computer_root(self, computer_root: bool) -> Self
pub fn with_computer_root(self, computer_root: bool) -> Self
Whether a Windows-style source lists its drives as a root above the
drive roots, as “This PC” does. With it, Up from C:\ goes to that
listing, which the source answers for the path \. Without it, a
drive root is its own parent.
Sourcepub fn is_windows(&self) -> bool
pub fn is_windows(&self) -> bool
Whether this is a Windows style.
Sourcepub fn is_separator(&self, c: char) -> bool
pub fn is_separator(&self, c: char) -> bool
Whether c separates the parts of a path when it is typed.
Sourcepub fn is_case_sensitive(&self) -> bool
pub fn is_case_sensitive(&self) -> bool
Whether names that differ only by case are different names.
Sourcepub fn has_computer_root(&self) -> bool
pub fn has_computer_root(&self) -> bool
Whether the source lists a root above the drives.
Whether a name is hidden by the style’s own rule: a leading dot on a POSIX style, nothing on a Windows style, where hidden is an attribute the source reads.
Sourcepub fn fold<'a>(&self, name: &'a str) -> Cow<'a, str>
pub fn fold<'a>(&self, name: &'a str) -> Cow<'a, str>
The name as the style compares it: lower case when case does not matter.
Sourcepub fn compare_names(&self, a: &str, b: &str) -> Ordering
pub fn compare_names(&self, a: &str, b: &str) -> Ordering
Orders two names the way a listing sorts them: without regard to case, then by the name itself, whatever the style’s case rule.
Sourcepub fn path(&self, text: impl AsRef<str>) -> SourcePath
pub fn path(&self, text: impl AsRef<str>) -> SourcePath
The path text names in this style.
Sourcepub fn normalize_pasted(
&self,
text: &str,
env: &dyn Fn(&str) -> Option<String>,
) -> String
pub fn normalize_pasted( &self, text: &str, env: &dyn Fn(&str) -> Option<String>, ) -> String
The path text for a pasted text: a file:// URL becomes a path,
and a Windows-style path loses its surrounding quotes and spaces,
takes the style’s separator, and has a lone drive letter made a
drive root. %NAME% in a Windows-style path is expanded through
env, and stays as it is when env does not know the name. A
POSIX-style path is left as it is: a Windows-looking path pasted
there is not guessed at.
Trait Implementations§
impl Copy for PathStyle
impl Eq for PathStyle
impl StructuralPartialEq for PathStyle
Auto Trait Implementations§
impl Freeze for PathStyle
impl RefUnwindSafe for PathStyle
impl Send for PathStyle
impl Sync for PathStyle
impl Unpin for PathStyle
impl UnsafeUnpin for PathStyle
impl UnwindSafe for PathStyle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().