use std::path::Path;
use std::{fs, io, path::PathBuf};
#[derive(Clone, Debug)]
pub struct OpenOptions(fs::OpenOptions);
impl OpenOptions {
pub fn new() -> Self {
OpenOptions(fs::OpenOptions::new())
}
pub fn read(&mut self, read: bool) -> &mut Self {
self.0.read(read);
self
}
pub fn write(&mut self, write: bool) -> &mut Self {
self.0.write(write);
self
}
pub fn append(&mut self, append: bool) -> &mut Self {
self.0.append(append);
self
}
pub fn truncate(&mut self, truncate: bool) -> &mut Self {
self.0.truncate(truncate);
self
}
pub fn create(&mut self, create: bool) -> &mut Self {
self.0.create(create);
self
}
pub fn create_new(&mut self, create_new: bool) -> &mut Self {
self.0.create_new(create_new);
self
}
pub fn open<P>(&self, path: P) -> io::Result<crate::File>
where
P: AsRef<Path> + Into<PathBuf>,
{
#[allow(deprecated)]
crate::File::from_options(path, self.options())
}
}
impl OpenOptions {
pub fn from_options(options: fs::OpenOptions) -> Self {
Self(options)
}
pub fn options(&self) -> &fs::OpenOptions {
&self.0
}
pub fn options_mut(&mut self) -> &mut fs::OpenOptions {
&mut self.0
}
}