Remove unnecessary lifetime markers

This commit is contained in:
topjohnwu 2023-06-12 05:05:57 -07:00
parent e9cf27eb5a
commit caae932117

View File

@ -3,7 +3,6 @@ use std::cmp::min;
use std::ffi::CStr; use std::ffi::CStr;
use std::fs::File; use std::fs::File;
use std::io::{BufRead, Read, Seek, SeekFrom, Write}; use std::io::{BufRead, Read, Seek, SeekFrom, Write};
use std::marker::PhantomData;
use std::ops::Deref; use std::ops::Deref;
use std::os::fd::{AsFd, BorrowedFd, IntoRawFd}; use std::os::fd::{AsFd, BorrowedFd, IntoRawFd};
use std::os::unix::io::{AsRawFd, FromRawFd, OwnedFd, RawFd}; use std::os::unix::io::{AsRawFd, FromRawFd, OwnedFd, RawFd};
@ -185,7 +184,7 @@ impl<T: Write> WriteExt for T {
} }
pub struct DirEntry<'a> { pub struct DirEntry<'a> {
dir: &'a Directory<'a>, dir: &'a Directory,
entry: &'a dirent, entry: &'a dirent,
d_name_len: usize, d_name_len: usize,
} }
@ -267,9 +266,8 @@ impl Deref for DirEntry<'_> {
} }
} }
pub struct Directory<'a> { pub struct Directory {
dirp: *mut libc::DIR, dirp: *mut libc::DIR,
_phantom: PhantomData<&'a libc::DIR>,
} }
pub enum WalkResult { pub enum WalkResult {
@ -278,13 +276,10 @@ pub enum WalkResult {
Skip, Skip,
} }
impl<'a> Directory<'a> { impl Directory {
pub fn open(path: &CStr) -> io::Result<Directory> { pub fn open(path: &CStr) -> io::Result<Directory> {
let dirp = unsafe { libc::opendir(path.as_ptr()) }.check_os_err()?; let dirp = unsafe { libc::opendir(path.as_ptr()) }.check_os_err()?;
Ok(Directory { Ok(Directory { dirp })
dirp,
_phantom: PhantomData,
})
} }
pub fn read(&mut self) -> io::Result<Option<DirEntry<'_>>> { pub fn read(&mut self) -> io::Result<Option<DirEntry<'_>>> {
@ -345,7 +340,7 @@ impl<'a> Directory<'a> {
} }
} }
impl Directory<'_> { impl Directory {
fn post_order_walk_impl<F: FnMut(&DirEntry) -> io::Result<WalkResult>>( fn post_order_walk_impl<F: FnMut(&DirEntry) -> io::Result<WalkResult>>(
&mut self, &mut self,
f: &mut F, f: &mut F,
@ -396,31 +391,28 @@ impl Directory<'_> {
} }
} }
impl TryFrom<OwnedFd> for Directory<'_> { impl TryFrom<OwnedFd> for Directory {
type Error = io::Error; type Error = io::Error;
fn try_from(fd: OwnedFd) -> io::Result<Self> { fn try_from(fd: OwnedFd) -> io::Result<Self> {
let dirp = unsafe { libc::fdopendir(fd.into_raw_fd()) }.check_os_err()?; let dirp = unsafe { libc::fdopendir(fd.into_raw_fd()) }.check_os_err()?;
Ok(Directory { Ok(Directory { dirp })
dirp,
_phantom: PhantomData,
})
} }
} }
impl AsRawFd for Directory<'_> { impl AsRawFd for Directory {
fn as_raw_fd(&self) -> RawFd { fn as_raw_fd(&self) -> RawFd {
unsafe { libc::dirfd(self.dirp) } unsafe { libc::dirfd(self.dirp) }
} }
} }
impl<'a> AsFd for Directory<'a> { impl AsFd for Directory {
fn as_fd(&self) -> BorrowedFd<'a> { fn as_fd(&self) -> BorrowedFd {
unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
} }
} }
impl Drop for Directory<'_> { impl Drop for Directory {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
libc::closedir(self.dirp); libc::closedir(self.dirp);