use std::{fmt, path::Path};
use crate::{a_sync::caches::CacheInstance, cfg_host_parser::HostConfig, ResolveConfig};
pub trait MutexedCaches: fmt::Debug
{
type MetadataFs: UnifiedFs;
type ResolveCache: AsyncMutex<CacheInstance<ResolveConfig, Self::MetadataFs>> + fmt::Debug;
type HostCahae: AsyncMutex<CacheInstance<HostConfig, Self::MetadataFs>> + fmt::Debug;
}
#[allow(async_fn_in_trait)]
pub trait UnifiedFs
{
type ErrRes: fmt::Display;
type FileOp;
async fn metadata(path: &Path) -> Result<std::fs::Metadata, Self::ErrRes>;
async fn open<P: AsRef<Path>>(path: P) -> std::io::Result<Self::FileOp>;
async fn read_to_string(file: &mut Self::FileOp, buf: &mut String) -> std::io::Result<usize>;
}
#[allow(async_fn_in_trait)]
pub trait AsyncMutex<DS: Sized>
{
type MutxGuard<'mux>: AsyncMutexGuard<'mux, DS> where Self: 'mux;
fn a_new(v: DS) -> Self;
async fn a_lock<'mux>(&'mux self) -> Self::MutxGuard<'mux>;
}
pub trait AsyncMutexGuard<'mux, DS: Sized>
{
fn guard(&self) -> &DS;
fn guard_mut(&mut self) -> &mut DS;
}