Skip to content

Commit

Permalink
ioctl/(de|en)coder_cmd: use From trait for error conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnurou committed Apr 13, 2023
1 parent da77170 commit 0de5c41
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
16 changes: 9 additions & 7 deletions lib/src/ioctl/decoder_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ impl From<DecoderCmdError> for Errno {
}
}

fn map_nix_error(error: Errno) -> DecoderCmdError {
match error {
Errno::EBUSY => DecoderCmdError::DrainInProgress,
Errno::EINVAL => DecoderCmdError::UnsupportedCommand,
e => DecoderCmdError::IoctlError(e),
impl From<Errno> for DecoderCmdError {
fn from(error: Errno) -> Self {
match error {
Errno::EBUSY => DecoderCmdError::DrainInProgress,
Errno::EINVAL => DecoderCmdError::UnsupportedCommand,
e => DecoderCmdError::IoctlError(e),
}
}
}

Expand All @@ -70,7 +72,7 @@ pub fn decoder_cmd<I: Into<bindings::v4l2_decoder_cmd>>(

match unsafe { ioctl::vidioc_decoder_cmd(fd.as_raw_fd(), &mut dec_cmd) } {
Ok(_) => Ok(()),
Err(e) => Err(map_nix_error(e)),
Err(e) => Err(e.into()),
}
}

Expand All @@ -82,6 +84,6 @@ pub fn try_decoder_cmd<I: Into<bindings::v4l2_decoder_cmd>>(

match unsafe { ioctl::vidioc_try_decoder_cmd(fd.as_raw_fd(), &mut dec_cmd) } {
Ok(_) => Ok(()),
Err(e) => Err(map_nix_error(e)),
Err(e) => Err(e.into()),
}
}
16 changes: 9 additions & 7 deletions lib/src/ioctl/encoder_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ impl From<EncoderCmdError> for Errno {
}
}

fn map_nix_error(error: Errno) -> EncoderCmdError {
match error {
Errno::EBUSY => EncoderCmdError::DrainInProgress,
Errno::EINVAL => EncoderCmdError::UnsupportedCommand,
e => EncoderCmdError::IoctlError(e),
impl From<Errno> for EncoderCmdError {
fn from(error: Errno) -> Self {
match error {
Errno::EBUSY => EncoderCmdError::DrainInProgress,
Errno::EINVAL => EncoderCmdError::UnsupportedCommand,
e => EncoderCmdError::IoctlError(e),
}
}
}

Expand Down Expand Up @@ -72,7 +74,7 @@ pub fn encoder_cmd<I: Into<bindings::v4l2_encoder_cmd>>(

match unsafe { ioctl::vidioc_encoder_cmd(fd.as_raw_fd(), &mut enc_cmd) } {
Ok(_) => Ok(()),
Err(e) => Err(map_nix_error(e)),
Err(e) => Err(e.into()),
}
}

Expand All @@ -84,6 +86,6 @@ pub fn try_encoder_cmd<I: Into<bindings::v4l2_encoder_cmd>>(

match unsafe { ioctl::vidioc_try_encoder_cmd(fd.as_raw_fd(), &mut enc_cmd) } {
Ok(_) => Ok(()),
Err(e) => Err(map_nix_error(e)),
Err(e) => Err(e.into()),
}
}

0 comments on commit 0de5c41

Please sign in to comment.