use std::path::{Path, PathBuf};
#[derive(Debug)]
pub struct WebContext<T: WebContextImpl> {
data: WebContextData,
#[allow(dead_code)] pub os: T,
}
impl<T: WebContextImpl> WebContext<T> {
pub fn new(data_directory: Option<PathBuf>) -> Self {
let data = WebContextData { data_directory };
let os = WebContextImpl::new(&data);
Self { data, os }
}
pub fn data_directory(&self) -> Option<&Path> {
self.data.data_directory()
}
pub fn set_allows_automation(&mut self, flag: bool) {
self.os.set_allows_automation(flag);
}
}
impl<T: WebContextImpl> Default for WebContext<T> {
fn default() -> Self {
let data = WebContextData::default();
let os = T::new(&data);
Self { data, os }
}
}
#[derive(Debug, Default)]
pub struct WebContextData {
data_directory: Option<PathBuf>,
}
impl WebContextData {
pub fn data_directory(&self) -> Option<&Path> {
self.data_directory.as_deref()
}
}
pub trait WebContextImpl {
fn new(_data: &WebContextData) -> Self;
fn set_allows_automation(&mut self, _flag: bool);
}