use std::{fs::OpenOptions, path::PathBuf};
use anyhow::Result;
use crate::RwBuilder;
#[derive(Debug)]
pub struct Builder {
path: PathBuf,
}
impl Builder {
#[must_use]
pub const fn new(path: PathBuf) -> Self {
Self { path }
}
}
impl RwBuilder for Builder {
type Reader = std::fs::File;
type Writer = std::fs::File;
fn reader(&self) -> Result<Self::Reader> {
let options = OpenOptions::new().read(true).open(&self.path)?;
Ok(options)
}
fn writer(&self) -> Result<Self::Writer> {
let options = OpenOptions::new().create(true).write(true).open(&self.path)?;
Ok(options)
}
}