Trait std::path::GenericPath
pub trait GenericPath: Clone + GenericPathUnsafe { fn as_vec<'a>(&'a self) -> &'a [u8]; fn into_vec(self) -> ~[u8]; fn dirname<'a>(&'a self) -> &'a [u8]; fn filename<'a>(&'a self) -> Option<&'a [u8]>; fn root_path(&self) -> Option<Self>; fn pop(&mut self) -> bool; fn is_absolute(&self) -> bool; fn is_ancestor_of(&self, other: &Self) -> bool; fn path_relative_from(&self, base: &Self) -> Option<Self>; fn ends_with_path(&self, child: &Self) -> bool; fn new<T: BytesContainer>(path: T) -> Self { ... } fn new_opt<T: BytesContainer>(path: T) -> Option<Self> { ... } fn as_str<'a>(&'a self) -> Option<&'a str> { ... } fn display<'a>(&'a self) -> Display<'a, Self> { ... } fn filename_display<'a>(&'a self) -> Display<'a, Self> { ... } fn dirname_str<'a>(&'a self) -> Option<&'a str> { ... } fn filename_str<'a>(&'a self) -> Option<&'a str> { ... } fn filestem<'a>(&'a self) -> Option<&'a [u8]> { ... } fn filestem_str<'a>(&'a self) -> Option<&'a str> { ... } fn extension<'a>(&'a self) -> Option<&'a [u8]> { ... } fn extension_str<'a>(&'a self) -> Option<&'a str> { ... } fn set_filename<T: BytesContainer>(&mut self, filename: T) { ... } fn set_extension<T: BytesContainer>(&mut self, extension: T) { ... } fn with_filename<T: BytesContainer>(&self, filename: T) -> Self { ... } fn with_extension<T: BytesContainer>(&self, extension: T) -> Self { ... } fn dir_path(&self) -> Self { ... } fn push<T: BytesContainer>(&mut self, path: T) { ... } fn push_many<T: BytesContainer>(&mut self, paths: &[T]) { ... } fn join<T: BytesContainer>(&self, path: T) -> Self { ... } fn join_many<T: BytesContainer>(&self, paths: &[T]) -> Self { ... } fn is_relative(&self) -> bool { ... } }
A trait that represents the generic operations available on paths
Required Methods
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 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 root_path(&self) -> Option<Self>
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 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 is_absolute(&self) -> bool
Returns whether self
represents an absolute path.
An absolute path is defined as one that, when joined to another path, will
yield back the same absolute path.
fn is_ancestor_of(&self, other: &Self) -> 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: &Self) -> Option<Self>
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: &Self) -> bool
Returns whether the relative path child
is a suffix of self
.
Provided Methods
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 new_opt<T: BytesContainer>(path: T) -> Option<Self>
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>
Returns the path as a string, if possible. If the path is not representable in utf-8, this returns None.
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 dirname_str<'a>(&'a self) -> Option<&'a str>
Returns the directory component of self
, as a string, if possible.
See dirname
for details.
fn filename_str<'a>(&'a self) -> Option<&'a str>
Returns the file component of self
, as a string, if possible.
See filename
for details.
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 filestem_str<'a>(&'a self) -> Option<&'a str>
Returns the stem of the filename of self
, as a string, if possible.
See filestem
for details.
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 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 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 dir_path(&self) -> Self
Returns the directory component of self
, as a Path.
If self
represents the root of the filesystem hierarchy, returns self
.
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.
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.