Skip to content

Commit

Permalink
ioctl: use the type field to determine FrmIvalTypes and FrmSizeTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunke Cao committed Oct 15, 2024
1 parent c81db81 commit 5bb297e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/src/ioctl/frameintervals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ pub enum FrmIvalTypes<'a> {

impl v4l2_frmivalenum {
/// Safely access the intervals member of the struct based on the
/// returned index.
/// returned type.
pub fn intervals(&self) -> Option<FrmIvalTypes> {
match self.index {
match self.type_ {
// SAFETY: the member of the union that gets used by the driver
// is determined by the index
// is determined by the type
bindings::v4l2_frmivaltypes_V4L2_FRMIVAL_TYPE_DISCRETE => {
Some(FrmIvalTypes::Discrete(unsafe {
&self.__bindgen_anon_1.discrete
}))
}

// SAFETY: the member of the union that gets used by the driver
// is determined by the index
// is determined by the type
bindings::v4l2_frmivaltypes_V4L2_FRMIVAL_TYPE_CONTINUOUS
| bindings::v4l2_frmivaltypes_V4L2_FRMIVAL_TYPE_STEPWISE => {
Some(FrmIvalTypes::StepWise(unsafe {
Expand Down
8 changes: 4 additions & 4 deletions lib/src/ioctl/framesizes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ pub enum FrmSizeTypes<'a> {

impl v4l2_frmsizeenum {
/// Safely access the size member of the struct based on the
/// returned index.
/// returned type.
pub fn size(&self) -> Option<FrmSizeTypes> {
match self.index {
match self.type_ {
// SAFETY: the member of the union that gets used by the driver
// is determined by the index
// is determined by the type
bindings::v4l2_frmsizetypes_V4L2_FRMSIZE_TYPE_DISCRETE => {
Some(FrmSizeTypes::Discrete(unsafe {
&self.__bindgen_anon_1.discrete
}))
}

// SAFETY: the member of the union that gets used by the driver
// is determined by the index
// is determined by the type
bindings::v4l2_frmsizetypes_V4L2_FRMSIZE_TYPE_CONTINUOUS
| bindings::v4l2_frmsizetypes_V4L2_FRMSIZE_TYPE_STEPWISE => {
Some(FrmSizeTypes::StepWise(unsafe {
Expand Down

0 comments on commit 5bb297e

Please sign in to comment.