Struct std::path::windows::Path
pub struct Path { // some fields omitted }
Represents a Windows path
Methods
impl Path
fn new<T: BytesContainer>(path: T) -> Path
Returns a new Path from a byte vector or string
Failure
Fails the task if the vector contains a NUL. Fails if invalid UTF-8.
fn new_opt<T: BytesContainer>(path: T) -> Option<Path>
Returns a new Path from a byte vector or string, if possible
fn str_components<'a>(&'a self) -> StrComponents<'a>
Returns an iterator that yields each component of the path in turn as a Option<&str>. Every component is guaranteed to be Some. Does not yield the path prefix (including server/share components in UNC paths). Does not distinguish between volume-relative and relative paths, e.g. \a\b\c and a\b\c. Does not distinguish between absolute and cwd-relative paths, e.g. C:\foo and C:foo.
fn rev_str_components<'a>(&'a self) -> RevStrComponents<'a>
Returns an iterator that yields each component of the path in reverse as an Option<&str> See str_components() for details.
fn components<'a>(&'a self) -> Components<'a>
Returns an iterator that yields each component of the path in turn as a &[u8]. See str_components() for details.
fn rev_components<'a>(&'a self) -> RevComponents<'a>
Returns an iterator that yields each component of the path in reverse as a &[u8]. See str_components() for details.
Trait Implementations
impl Eq for Path
impl TotalEq for Path
impl FromStr for Path
fn from_str(s: &str) -> Option<Path>
Parses a string s
to return an optional value of this type. If the
string is ill-formatted, the None is returned.
impl ToCStr for Path
fn to_c_str(&self) -> CString
unsafe fn to_c_str_unchecked(&self) -> CString
Unsafe variant of to_c_str()
that doesn't check for nulls.
fn with_c_str<T>(&self, f: |*c_char| -> T) -> T
Work with a temporary CString constructed from the receiver.
The provided *libc::c_char
will be freed immediately upon return.
Example
use std::libc; let s = "PATH".with_c_str(|path| unsafe { libc::getenv(path) });
Failure
Fails the task if the receiver has an interior null.
unsafe fn with_c_str_unchecked<T>(&self, f: |*c_char| -> T) -> T
Unsafe variant of with_c_str()
that doesn't check for nulls.
impl<S: Writer> Hash<S> for Path
fn hash(&self, state: &mut S)
Compute a hash of the value.
impl BytesContainer for Path
fn container_as_bytes<'a>(&'a self) -> &'a [u8]
Returns a &[u8] representing the receiver
fn container_into_owned_bytes(self) -> ~[u8]
Consumes the receiver and converts it into ~[u8]
fn container_as_str<'a>(&'a self) -> Option<&'a str>
Returns the receiver interpreted as a utf-8 string, if possible
fn is_str(_: Option<Path>) -> bool
Returns whether .container_as_str() is guaranteed to not fail
impl GenericPathUnsafe for Path
unsafe fn new_unchecked<T: BytesContainer>(path: T) -> Path
unsafe fn set_filename_unchecked<T: BytesContainer>(&mut self, filename: T)
unsafe fn push_unchecked<T: BytesContainer>(&mut self, path: T)
See GenericPathUnsafe::push_unchecked
.
Concatenating two Windows Paths is rather complicated.
For the most part, it will behave as expected, except in the case of
pushing a volume-relative path, e.g. C:foo.txt
. Because we have no
concept of per-volume cwds like Windows does, we can't behave exactly
like Windows will. Instead, if the receiver is an absolute path on
the same volume as the new path, it will be treated as the cwd that
the new path is relative to. Otherwise, the new path will be treated
as if it were absolute and will replace the receiver outright.
impl GenericPath for Path
fn new_opt<T: BytesContainer>(path: T) -> Option<Path>
Creates a new Path from a byte vector or string, if possible. The resulting Path will always be normalized.
fn as_str<'a>(&'a self) -> Option<&'a str>
See GenericPath::as_str
for info.
Always returns a Some
value.
fn as_vec<'a>(&'a self) -> &'a [u8]
Returns the path as a byte vector
fn into_vec(self) -> ~[u8]
Converts the Path into an owned byte vector
fn dirname<'a>(&'a self) -> &'a [u8]
Returns the directory component of self
, as a byte vector (with no trailing separator).
If self
has no directory component, returns ['.'].
fn dirname_str<'a>(&'a self) -> Option<&'a str>
See GenericPath::dirname_str
for info.
Always returns a Some
value.
fn filename<'a>(&'a self) -> Option<&'a [u8]>
Returns the file component of self
, as a byte vector.
If self
represents the root of the file hierarchy, returns None.
If self
is "." or "..", returns None.
fn filename_str<'a>(&'a self) -> Option<&'a str>
See GenericPath::filename_str
for info.
Always returns a Some
value if filename
returns a Some
value.
fn filestem_str<'a>(&'a self) -> Option<&'a str>
See GenericPath::filestem_str
for info.
Always returns a Some
value if filestem
returns a Some
value.
fn extension_str<'a>(&'a self) -> Option<&'a str>
Returns the extension of the filename of self
, as a string, if possible.
See extension
for details.
fn dir_path(&self) -> Path
Returns the directory component of self
, as a Path.
If self
represents the root of the filesystem hierarchy, returns self
.
fn pop(&mut self) -> bool
Removes the last path component from the receiver.
Returns true
if the receiver was modified, or false
if it already
represented the root of the file hierarchy.
fn root_path(&self) -> Option<Path>
Returns a Path that represents the filesystem root that self
is rooted in.
If self
is not absolute, or vol/cwd-relative in the case of Windows, this returns None.
fn is_absolute(&self) -> bool
See GenericPath::is_absolute
for info.
A Windows Path is considered absolute only if it has a non-volume prefix,
or if it has a volume prefix and the path starts with '\'.
A path of \foo
is not considered absolute because it's actually
relative to the "current volume". A separate method Path::is_vol_relative
is provided to indicate this case. Similarly a path of C:foo
is not
considered absolute because it's relative to the cwd on volume C:. A
separate method Path::is_cwd_relative
is provided to indicate this case.
fn is_relative(&self) -> bool
Returns whether self
represents a relative path.
Typically this is the inverse of is_absolute
.
But for Windows paths, it also means the path is not volume-relative or
relative to the current working directory.
fn is_ancestor_of(&self, other: &Path) -> bool
Returns whether self
is equal to, or is an ancestor of, the given path.
If both paths are relative, they are compared as though they are relative
to the same parent path.
fn path_relative_from(&self, base: &Path) -> Option<Path>
Returns the Path that, were it joined to base
, would yield self
.
If no such path exists, None is returned.
If self
is absolute and base
is relative, or on Windows if both
paths refer to separate drives, an absolute path is returned.
fn ends_with_path(&self, child: &Path) -> bool
Returns whether the relative path child
is a suffix of self
.
fn new<T: BytesContainer>(path: T) -> Self
Creates a new Path from a byte vector or string. The resulting Path will always be normalized.
Failure
Fails the task if the path contains a NUL.
See individual Path impls for additional restrictions.
fn display<'a>(&'a self) -> Display<'a, Self>
Returns an object that implements Show
for printing paths
This will print the equivalent of to_display_str()
when used with a {} format parameter.
fn filename_display<'a>(&'a self) -> Display<'a, Self>
Returns an object that implements Show
for printing filenames
This will print the equivalent of to_filename_display_str()
when used with a {}
format parameter. If there is no filename, nothing will be printed.
fn filestem<'a>(&'a self) -> Option<&'a [u8]>
Returns the stem of the filename of self
, as a byte vector.
The stem is the portion of the filename just before the last '.'.
If there is no '.', the entire filename is returned.
fn extension<'a>(&'a self) -> Option<&'a [u8]>
Returns the extension of the filename of self
, as an optional byte vector.
The extension is the portion of the filename just after the last '.'.
If there is no extension, None is returned.
If the filename ends in '.', the empty vector is returned.
fn set_filename<T: BytesContainer>(&mut self, filename: T)
Replaces the filename portion of the path with the given byte vector or string. If the replacement name is [], this is equivalent to popping the path.
Failure
Fails the task if the filename contains a NUL.
fn set_extension<T: BytesContainer>(&mut self, extension: T)
Replaces the extension with the given byte vector or string.
If there is no extension in self
, this adds one.
If the argument is [] or "", this removes the extension.
If self
has no filename, this is a no-op.
Failure
Fails the task if the extension contains a NUL.
fn with_filename<T: BytesContainer>(&self, filename: T) -> Self
Returns a new Path constructed by replacing the filename with the given
byte vector or string.
See set_filename
for details.
Failure
Fails the task if the filename contains a NUL.
fn with_extension<T: BytesContainer>(&self, extension: T) -> Self
Returns a new Path constructed by setting the extension to the given
byte vector or string.
See set_extension
for details.
Failure
Fails the task if the extension contains a NUL.
fn push<T: BytesContainer>(&mut self, path: T)
Pushes a path (as a byte vector or string) onto self
.
If the argument represents an absolute path, it replaces self
.
Failure
Fails the task if the path contains a NUL.
fn push_many<T: BytesContainer>(&mut self, paths: &[T])
Pushes multiple paths (as byte vectors or strings) onto self
.
See push
for details.
fn join<T: BytesContainer>(&self, path: T) -> Self
Returns a new Path constructed by joining self
with the given path
(as a byte vector or string).
If the given path is absolute, the new Path will represent just that.
Failure
Fails the task if the path contains a NUL.
fn join_many<T: BytesContainer>(&self, paths: &[T]) -> Self
Returns a new Path constructed by joining self
with the given paths
(as byte vectors or strings).
See join
for details.
Derived Implementations
impl Clone for Path
fn clone(&self) -> Path
Returns a copy of the value. The contents of owned pointers are copied to maintain uniqueness, while the contents of managed pointers are not copied.
fn clone_from(&mut self, source: &Self)
Perform copy-assignment from source
.
a.clone_from(&b)
is equivalent to a = b.clone()
in functionality,
but can be overridden to reuse the resources of a
to avoid unnecessary
allocations.