Struct path_abs::PathFile [] [src]

pub struct PathFile(_);

a PathAbs that is guaranteed to be a file, with associated methods.

Methods

impl PathFile
[src]

[src]

Instantiate a new PathFile. The file must exist or io::Error will be returned.

Returns io::ErrorKind::InvalidInput if the path exists but is not a file.

Examples

use path_abs::PathFile;

let lib = PathFile::new("src/lib.rs").unwrap();

[src]

Consume the PathAbs validating that the path is a file and returning PathFile. The file must exist or io::Error will be returned.

If the path is actually a dir returns io::ErrorKind::InvalidInput.

This does not call Path::cannonicalize(), instead trusting that the input already a fully qualified path.

Examples

use path_abs::{PathAbs, PathFile};

let lib_abs = PathAbs::new("src/lib.rs").unwrap();
let lib_file = PathFile::from_abs(lib_abs).unwrap();

[src]

Instantiate a new PathFile, creating it first if it doesn't exist.

Examples

use path_abs::PathFile;


let example = "target/example.txt";


let file = PathFile::create(example).unwrap();

// It can be done twice with no effect.
let _ = PathFile::create(example).unwrap();

[src]

Read the entire contents of the file into a String.

Examples

use path_abs::PathFile;


let example = "target/example.txt";
let file = PathFile::create(example).unwrap();

let expected = "foo\nbar";
file.write_str(expected).unwrap();
assert_eq!(expected, file.read_string().unwrap());

[src]

Write the str to a file, truncating it first if it exist and creating it otherwise.

Examples

use path_abs::PathFile;


let example = "target/example.txt";
let file = PathFile::create(example).unwrap();

let expected = "foo\nbar";
file.write_str(expected).unwrap();
assert_eq!(expected, file.read_string().unwrap());

[src]

Append the str to a file, creating it if it doesn't exist.

If the str is empty, this is equivalent to the unix touch except it does NOT update the timestamp

Examples

use path_abs::PathFile;

let example = "target/example.txt";
let file = PathFile::create(example).unwrap();

let expected = "foo\nbar\nbaz";
file.append_str("foo\nbar").unwrap();
file.append_str("\nbaz").unwrap();
assert_eq!(expected, file.read_string().unwrap());

[src]

Create a mock file type. For use in tests only.

See the docs for PathAbs::mock

Methods from Deref<Target = PathAbs>

[src]

Resolve the PathAbs as a PathFile. Return an error if it is not a file.

[src]

Resolve the PathAbs as a PathDir. Return an error if it is not a directory.

[src]

Get the parent directory of this path as a PathDir.

This does not make additinal syscalls, as the parent by definition must be a directory and exist.

Examples

use path_abs::{PathDir, PathFile};

let lib = PathFile::new("src/lib.rs").unwrap();
let src = lib.parent_dir().unwrap();
assert_eq!(PathDir::new("src").unwrap(), src);

Trait Implementations

impl Clone for PathFile
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Eq for PathFile
[src]

impl Hash for PathFile
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl PartialEq for PathFile
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl PartialOrd for PathFile
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

[src]

This method tests less than (for self and other) and is used by the < operator. Read more

[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl Ord for PathFile
[src]

[src]

This method returns an Ordering between self and other. Read more

1.22.0
[src]

Compares and returns the maximum of two values. Read more

1.22.0
[src]

Compares and returns the minimum of two values. Read more

impl Debug for PathFile
[src]

[src]

Formats the value using the given formatter.

impl AsRef<PathAbs> for PathFile
[src]

[src]

Performs the conversion.

impl AsRef<Path> for PathFile
[src]

[src]

Performs the conversion.

impl AsRef<PathBuf> for PathFile
[src]

[src]

Performs the conversion.

impl Deref for PathFile
[src]

The resulting type after dereferencing.

[src]

Dereferences the value.

impl Serialize for PathFile
[src]

[src]

Serialize this value into the given Serde serializer. Read more

impl<'de> Deserialize<'de> for PathFile
[src]

[src]

Deserialize this value from the given Serde deserializer. Read more