use super::OpenFuture;
use std::convert::From;
use std::fs::OpenOptions as StdOpenOptions;
use std::path::Path;
#[derive(Clone, Debug)]
pub struct OpenOptions(StdOpenOptions);
impl OpenOptions {
pub fn new() -> OpenOptions {
OpenOptions(StdOpenOptions::new())
}
pub fn read(&mut self, read: bool) -> &mut OpenOptions {
self.0.read(read);
self
}
pub fn write(&mut self, write: bool) -> &mut OpenOptions {
self.0.write(write);
self
}
pub fn append(&mut self, append: bool) -> &mut OpenOptions {
self.0.append(append);
self
}
pub fn truncate(&mut self, truncate: bool) -> &mut OpenOptions {
self.0.truncate(truncate);
self
}
pub fn create(&mut self, create: bool) -> &mut OpenOptions {
self.0.create(create);
self
}
pub fn create_new(&mut self, create_new: bool) -> &mut OpenOptions {
self.0.create_new(create_new);
self
}
pub fn open<P>(&self, path: P) -> OpenFuture<P>
where
P: AsRef<Path> + Send + 'static,
{
OpenFuture::new(self.0.clone(), path)
}
}
impl From<StdOpenOptions> for OpenOptions {
fn from(options: StdOpenOptions) -> OpenOptions {
OpenOptions(options)
}
}