#[cfg(unix)]
#[path = "unix.rs"]
mod sys;
#[cfg(windows)]
#[path = "windows.rs"]
mod sys;
use std::{io, path::Path};
use crate::File;
#[derive(Debug, Clone)]
pub struct OpenOptions(sys::OpenOptions);
impl OpenOptions {
#[allow(clippy::new_without_default)]
#[must_use]
pub fn new() -> Self {
Self(sys::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 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 async fn open(&self, path: impl AsRef<Path>) -> io::Result<File> {
self.0.open(path).await
}
}
#[cfg(unix)]
impl OpenOptions {
pub fn custom_flags(&mut self, flags: i32) -> &mut Self {
self.0.custom_flags(flags);
self
}
pub fn mode(&mut self, mode: u32) -> &mut Self {
self.0.mode(mode);
self
}
}
#[cfg(windows)]
impl OpenOptions {
pub fn custom_flags(&mut self, flags: u32) -> &mut Self {
self.0.custom_flags(flags);
self
}
pub fn access_mode(&mut self, access_mode: u32) -> &mut Self {
self.0.access_mode(access_mode);
self
}
pub fn share_mode(&mut self, share_mode: u32) -> &mut Self {
self.0.share_mode(share_mode);
self
}
pub fn attributes(&mut self, attrs: u32) -> &mut Self {
self.0.attributes(attrs);
self
}
pub fn security_qos_flags(&mut self, flags: u32) -> &mut Self {
self.0.security_qos_flags(flags);
self
}
}