Struct path_abs::PathFile
[−]
[src]
pub struct PathFile(_);
a PathAbs
that is guaranteed to be a file, with associated methods.
Methods
impl PathFile
[src]
fn new<P: AsRef<Path>>(path: P) -> Result<PathFile>
[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();
fn from_abs(abs: PathAbs) -> Result<PathFile>
[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();
fn create<P: AsRef<Path>>(path: P) -> Result<PathFile>
[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();
fn read_string(&self) -> Result<String>
[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());
fn write_str(&self, s: &str) -> Result<()>
[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());
fn append_str(&self, s: &str) -> Result<()>
[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());
fn mock<P: AsRef<Path>>(path: P) -> PathFile
[src]
Create a mock file type. For use in tests only.
See the docs for PathAbs::mock
Methods from Deref<Target = PathAbs>
fn into_file(self) -> Result<PathFile>
[src]
Resolve the PathAbs
as a PathFile
. Return an error if it is not a file.
fn into_dir(self) -> Result<PathDir>
[src]
Resolve the PathAbs
as a PathDir
. Return an error if it is not a directory.
fn parent_dir(&self) -> Option<PathDir>
[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]
fn clone(&self) -> PathFile
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Eq for PathFile
[src]
impl Hash for PathFile
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl PartialEq for PathFile
[src]
fn eq(&self, __arg_0: &PathFile) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &PathFile) -> bool
[src]
This method tests for !=
.
impl PartialOrd for PathFile
[src]
fn partial_cmp(&self, __arg_0: &PathFile) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &PathFile) -> bool
[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &PathFile) -> bool
[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &PathFile) -> bool
[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &PathFile) -> bool
[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]
fn cmp(&self, __arg_0: &PathFile) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.22.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.22.0[src]
Compares and returns the minimum of two values. Read more
impl Debug for PathFile
[src]
impl AsRef<PathAbs> for PathFile
[src]
impl AsRef<Path> for PathFile
[src]
impl AsRef<PathBuf> for PathFile
[src]
impl Deref for PathFile
[src]
type Target = PathAbs
The resulting type after dereferencing.
fn deref(&self) -> &PathAbs
[src]
Dereferences the value.
impl Serialize for PathFile
[src]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
S: Serializer,
[src]
S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl<'de> Deserialize<'de> for PathFile
[src]
fn deserialize<D>(deserializer: D) -> Result<PathFile, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more