Skip to content

Commit

Permalink
Remove FdError, and just use InvalidFdError
Browse files Browse the repository at this point in the history
Now this only has one variant, there's no need for an enum.
  • Loading branch information
ids1024 committed Dec 2, 2024
1 parent 11d4722 commit d433a79
Showing 1 changed file with 4 additions and 33 deletions.
37 changes: 4 additions & 33 deletions src/buffer_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,12 @@ impl<T: 'static> BufferObject<T> {
/// 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<OwnedFd, FdError> {
pub fn fd(&self) -> Result<OwnedFd, InvalidFdError> {
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))
Expand All @@ -266,12 +266,12 @@ impl<T: 'static> BufferObject<T> {
/// 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<OwnedFd, FdError> {
pub fn fd_for_plane(&self, plane: i32) -> Result<OwnedFd, InvalidFdError> {
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))
Expand Down Expand Up @@ -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<InvalidFdError> 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),
}
}
}

0 comments on commit d433a79

Please sign in to comment.