use crate::{
error::Error,
flags::OpenFlags,
procfs::{ProcfsBase, ProcfsHandleRef},
tests::traits::ErrorImpl,
};
use std::{
fs::File,
path::{Path, PathBuf},
};
pub(in crate::tests) trait ProcfsHandleImpl: std::fmt::Debug {
type Error: ErrorImpl;
fn open_follow(
&self,
base: ProcfsBase,
subpath: impl AsRef<Path>,
flags: impl Into<OpenFlags>,
) -> Result<File, Self::Error>;
fn open(
&self,
base: ProcfsBase,
subpath: impl AsRef<Path>,
flags: impl Into<OpenFlags>,
) -> Result<File, Self::Error>;
fn readlink(&self, base: ProcfsBase, subpath: impl AsRef<Path>)
-> Result<PathBuf, Self::Error>;
}
impl<'fd> ProcfsHandleImpl for ProcfsHandleRef<'fd> {
type Error = Error;
fn open_follow(
&self,
base: ProcfsBase,
subpath: impl AsRef<Path>,
flags: impl Into<OpenFlags>,
) -> Result<File, Self::Error> {
self.open_follow(base, subpath, flags)
}
fn open(
&self,
base: ProcfsBase,
subpath: impl AsRef<Path>,
flags: impl Into<OpenFlags>,
) -> Result<File, Self::Error> {
self.open(base, subpath, flags)
}
fn readlink(
&self,
base: ProcfsBase,
subpath: impl AsRef<Path>,
) -> Result<PathBuf, Self::Error> {
self.readlink(base, subpath)
}
}