Added open_read, open_write and open_append convenience methods

This commit is contained in:
Josh Mitchell
2020-11-08 00:43:29 +11:00
parent 4a99228d87
commit 0351857606

View File

@@ -10,9 +10,8 @@
//! use xdrfile::*;
//! use std::path::Path;
//!
//! let mut path = Path::new("tests/1l2y.xtc");
//! // get a handle to the file
//! let mut trj = XTCTrajectory::open(path, FileMode::Read).unwrap();
//! let mut trj = XTCTrajectory::open_read("tests/1l2y.xtc").unwrap();
//!
//! // find number of atoms in the file
//! let num_atoms = trj.get_num_atoms().unwrap();
@@ -220,6 +219,21 @@ impl XTCTrajectory {
num_atoms: Lazy::new(),
})
}
/// Open a file in read mode
pub fn open_read(path: impl AsRef<Path>) -> Result<Self> {
Self::open(path, FileMode::Read)
}
/// Open a file in append mode
pub fn open_append(path: impl AsRef<Path>) -> Result<Self> {
Self::open(path, FileMode::Append)
}
/// Open a file in write mode
pub fn open_write(path: impl AsRef<Path>) -> Result<Self> {
Self::open(path, FileMode::Write)
}
}
impl Trajectory for XTCTrajectory {
@@ -307,6 +321,21 @@ impl TRRTrajectory {
num_atoms: Lazy::new(),
})
}
/// Open a file in read mode
pub fn open_read(path: impl AsRef<Path>) -> Result<Self> {
Self::open(path, FileMode::Read)
}
/// Open a file in append mode
pub fn open_append(path: impl AsRef<Path>) -> Result<Self> {
Self::open(path, FileMode::Append)
}
/// Open a file in write mode
pub fn open_write(path: impl AsRef<Path>) -> Result<Self> {
Self::open(path, FileMode::Write)
}
}
impl Trajectory for TRRTrajectory {