From d433a793d00b616adc99e80eb5e47a5a53aea656 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Mon, 2 Dec 2024 09:06:15 -0800 Subject: [PATCH] Remove `FdError`, and just use `InvalidFdError` Now this only has one variant, there's no need for an enum. --- src/buffer_object.rs | 37 ++++--------------------------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/src/buffer_object.rs b/src/buffer_object.rs index 1995500..7584b7e 100644 --- a/src/buffer_object.rs +++ b/src/buffer_object.rs @@ -235,12 +235,12 @@ impl BufferObject { /// handle for the buffer object. Each call to [`Self::fd()`] returns a new /// file descriptor and the caller is responsible for closing the file /// descriptor. - pub fn fd(&self) -> Result { + pub fn fd(&self) -> Result { unsafe { let fd = ffi::gbm_bo_get_fd(*self.ffi); if fd == -1 { - return Err(InvalidFdError.into()); + return Err(InvalidFdError); } Ok(OwnedFd::from_raw_fd(fd)) @@ -266,12 +266,12 @@ impl BufferObject { /// handle for a plane of the buffer object. Each call to [`Self::fd_for_plane()`] /// returns a new file descriptor and the caller is responsible for closing /// the file descriptor. - pub fn fd_for_plane(&self, plane: i32) -> Result { + pub fn fd_for_plane(&self, plane: i32) -> Result { unsafe { let fd = ffi::gbm_bo_get_fd_for_plane(*self.ffi, plane); if fd == -1 { - return Err(InvalidFdError.into()); + return Err(InvalidFdError); } Ok(OwnedFd::from_raw_fd(fd)) @@ -596,32 +596,3 @@ impl fmt::Display for InvalidFdError { } impl error::Error for InvalidFdError {} - -/// Thrown when an error occurs during getting a bo fd -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum FdError { - /// The operation returned an invalid fd - InvalidFd(InvalidFdError), -} - -impl From for FdError { - fn from(err: InvalidFdError) -> Self { - FdError::InvalidFd(err) - } -} - -impl fmt::Display for FdError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - FdError::InvalidFd(err) => err.fmt(f), - } - } -} - -impl error::Error for FdError { - fn source(&self) -> Option<&(dyn error::Error + 'static)> { - match self { - FdError::InvalidFd(err) => Some(err), - } - } -}