use super::{File, FileSystemOpenOptions, current};
use std::io;
use std::path::Path;
#[derive(Clone, Debug, Default)]
pub struct OpenOptions {
pub(super) read: bool,
pub(super) write: bool,
pub(super) append: bool,
pub(super) truncate: bool,
pub(super) create: bool,
pub(super) create_new: bool,
}
impl OpenOptions {
pub fn new() -> Self {
Self::default()
}
pub fn read(&mut self, read: bool) -> &mut Self {
self.read = read;
self
}
pub fn write(&mut self, write: bool) -> &mut Self {
self.write = write;
self
}
pub fn append(&mut self, append: bool) -> &mut Self {
self.append = append;
self
}
pub fn truncate(&mut self, truncate: bool) -> &mut Self {
self.truncate = truncate;
self
}
pub fn create(&mut self, create: bool) -> &mut Self {
self.create = create;
self
}
pub fn create_new(&mut self, create_new: bool) -> &mut Self {
self.create_new = create_new;
self
}
pub async fn open(&self, path: impl AsRef<Path>) -> io::Result<File> {
current().open_with(self, path).await
}
}