[src]

Struct std::path::posix::Path

pub struct Path {
    // some fields omitted
}

Represents a POSIX file path

Methods

impl Path

fn stat(&self) -> IoResult<FileStat>

Get information on the file, directory, etc at this path.

Consult the file::stat documentation for more info.

This call preserves identical runtime/error semantics with file::stat.

fn exists(&self) -> bool

Boolean value indicator whether the underlying file exists on the local filesystem. This will return true if the path points to either a directory or a file.

Error

Will not raise a condition

fn is_file(&self) -> bool

Whether the underlying implementation (be it a file path, or something else) points at a "regular file" on the FS. Will return false for paths to non-existent locations or directories or other non-regular files (named pipes, etc).

Error

Will not raise a condition

fn is_dir(&self) -> bool

Whether the underlying implementation (be it a file path, or something else) is pointing at a directory in the underlying FS. Will return false for paths to non-existent locations or if the item is not a directory (eg files, named pipes, links, etc)

Error

Will not raise a condition

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.

fn new_opt<T: BytesContainer>(path: T) -> Option<Path>

Returns a new Path from a byte vector or string, if possible

fn components<'a>(&'a self) -> Components<'a>

Returns an iterator that yields each component of the path in turn. Does not distinguish between absolute and relative paths, e.g. /a/b/c and a/b/c yield the same set of components. A path of "/" yields no components. A path of "." yields one component.

fn rev_components<'a>(&'a self) -> RevComponents<'a>

Returns an iterator that yields each component of the path in reverse. See components() for details.

fn str_components<'a>(&'a self) -> StrComponents<'a>

Returns an iterator that yields each component of the path as Option<&str>. See components() for details.

fn rev_str_components<'a>(&'a self) -> RevStrComponents<'a>

Returns an iterator that yields each component of the path in reverse as Option<&str>. See components() for details.

Trait Implementations

impl Eq for Path

fn eq(&self, other: &Path) -> bool

fn ne(&self, other: &Self) -> bool

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

Copy the receiver into a CString.

Failure

Fails the task if the receiver has an interior null.

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<Self>) -> bool

Returns whether .container_as_str() is guaranteed to not fail

impl GenericPathUnsafe for Path

unsafe fn new_unchecked<T: BytesContainer>(path: T) -> Path

Creates a new Path without checking for null bytes. The resulting Path will always be normalized.

unsafe fn set_filename_unchecked<T: BytesContainer>(&mut self, filename: T)

Replaces the filename portion of the path without checking for null bytes. See set_filename for details.

unsafe fn push_unchecked<T: BytesContainer>(&mut self, path: T)

Pushes a path onto self without checking for null bytes. See push for details.

impl GenericPath for Path

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 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

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: &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 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.

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.