use tokio::{fs::File, io::AsyncReadExt, sync::{Mutex, MutexGuard}};
use crate::{a_sync::{caches::CacheInstance, interface::{AsyncMutex, AsyncMutexGuard, MutexedCaches, UnifiedFs}}, cfg_host_parser::HostConfig, ResolveConfig};
#[derive(Debug)]
pub struct TokioInterf;
impl MutexedCaches for TokioInterf
{
type MetadataFs = File;
type ResolveCache = Mutex<CacheInstance<ResolveConfig, Self::MetadataFs>>;
type HostCahae = Mutex<CacheInstance<HostConfig, Self::MetadataFs>>;
}
impl UnifiedFs for File
{
type ErrRes = std::io::Error;
type FileOp = Self;
async
fn metadata(path: &std::path::Path) -> Result<std::fs::Metadata, Self::ErrRes>
{
return tokio::fs::metadata(path).await;
}
async
fn open<P: AsRef<std::path::Path>>(path: P) -> std::io::Result<Self::FileOp>
{
return tokio::fs::File::open(path).await;
}
async
fn read_to_string(file: &mut Self::FileOp, buf: &mut String) -> std::io::Result<usize>
{
return file.read_to_string(buf).await;
}
}
impl<DS: Sized> AsyncMutex<DS> for Mutex<DS>
{
type MutxGuard<'mux> = MutexGuard<'mux, DS> where DS: 'mux;
fn a_new(v: DS) -> Self
{
return Mutex::new(v);
}
fn a_lock<'mux>(&'mux self) -> impl Future<Output = Self::MutxGuard<'mux>>
{
return self.lock();
}
}
impl<'mux, DS: Sized> AsyncMutexGuard<'mux, DS>for MutexGuard<'mux, DS>
{
fn guard(&self) -> &DS
{
return self;
}
fn guard_mut(&mut self) -> &mut DS
{
return self;
}
}