use crate::fs::{FileType, Metadata, OpenOptions};
use crate::fs_utf8::{to_utf8, Dir, File};
#[cfg(not(windows))]
use rustix::fs::DirEntryExt;
use std::{fmt, io};
pub struct DirEntry {
cap_std: crate::fs::DirEntry,
}
impl DirEntry {
#[inline]
pub fn from_cap_std(cap_std: crate::fs::DirEntry) -> Self {
Self { cap_std }
}
#[inline]
pub fn open(&self) -> io::Result<File> {
self.cap_std.open().map(File::from_cap_std)
}
#[inline]
pub fn open_with(&self, options: &OpenOptions) -> io::Result<File> {
self.cap_std.open_with(options).map(File::from_cap_std)
}
#[inline]
pub fn open_dir(&self) -> io::Result<Dir> {
self.cap_std.open_dir().map(Dir::from_cap_std)
}
#[inline]
pub fn remove_file(&self) -> io::Result<()> {
self.cap_std.remove_file()
}
#[inline]
pub fn remove_dir(&self) -> io::Result<()> {
self.cap_std.remove_dir()
}
#[inline]
pub fn metadata(&self) -> io::Result<Metadata> {
self.cap_std.metadata()
}
#[inline]
pub async fn file_type(&self) -> io::Result<FileType> {
self.cap_std.file_type().await
}
#[inline]
pub fn file_name(&self) -> io::Result<String> {
Ok(to_utf8(self.cap_std.file_name())?.into())
}
}
#[cfg(not(windows))]
impl DirEntryExt for DirEntry {
#[inline]
fn ino(&self) -> u64 {
self.cap_std.ino()
}
}
#[cfg(windows)]
#[doc(hidden)]
impl cap_primitives::fs::_WindowsDirEntryExt for DirEntry {
#[inline]
fn full_metadata(&self) -> io::Result<Metadata> {
self.cap_std.full_metadata()
}
}
impl fmt::Debug for DirEntry {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.cap_std.fmt(f)
}
}