Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some small Clippy lints + format Cargo.toml #112

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ authors = ["Christopher N. Hesse <[email protected]>"]
edition = "2018"
license = "MIT"
readme = "README.md"
repository= "https://github.com/raymanfx/libv4l-rs"
repository = "https://github.com/raymanfx/libv4l-rs"

[dependencies]
bitflags = "2"
libc = "0.2"
v4l-sys = { path = "v4l-sys", version = "0.3.0", optional = true }
v4l2-sys = { path = "v4l2-sys", version = "0.3.0", package="v4l2-sys-mit", optional = true }
v4l2-sys = { path = "v4l2-sys", version = "0.3.0", package = "v4l2-sys-mit", optional = true }

[dev-dependencies]
glium = "0.34"
Expand All @@ -25,7 +25,4 @@ libv4l = ["v4l-sys"]
v4l2 = ["v4l2-sys"]

[workspace]
members = [
"v4l-sys",
"v4l2-sys",
]
members = ["v4l-sys", "v4l2-sys"]
1 change: 1 addition & 0 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub enum Type {
MetaOutput = 14,

/// Deprecated, do not use
#[deprecated]
Comment on lines 28 to +29
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Deprecated, do not use
#[deprecated]
#[deprecated = "do not use"]

?

Private = 0x80,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this may not be useful. If you have a better reason than "do not use", it'd work much better here! :D

Suggested change
Private = 0x80,
#[deprecated(note = "do not use")]
Private = 0x80,

}

Expand Down
6 changes: 2 additions & 4 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,8 @@ impl Device {
Err(e) => {
if controls.is_empty() || e.kind() != io::ErrorKind::InvalidInput {
return Err(e);
} else {
break;
}
break;
}
Comment on lines 156 to 161
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could've almost written something like break if ... { Err(e) } else { Ok(controls) }; showing that this is the only exit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woah, that works just fine! I'm somewhat unfamiliar with this syntax, so please do check to ensure it's right:

Suggested change
Err(e) => {
if controls.is_empty() || e.kind() != io::ErrorKind::InvalidInput {
return Err(e);
} else {
break;
}
break;
}
Err(e) => {
break if controls.is_empty() || e.kind() != io::ErrorKind::InvalidInput {
Err(e)
} else {
Ok(controls)
};

}
}
Expand Down Expand Up @@ -250,9 +249,8 @@ impl Device {
io::ErrorKind::InvalidInput,
"All controls must be in the same class",
));
} else {
Some(c)
}
Some(c)
}
None => Some(control.id & 0xFFFF0000),
};
Expand Down
4 changes: 2 additions & 2 deletions src/io/mmap/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct Arena<'a> {
pub buf_type: buffer::Type,
}

impl<'a> Arena<'a> {
impl Arena<'_> {
/// Returns a new buffer manager instance
///
/// You usually do not need to use this directly.
Expand Down Expand Up @@ -118,7 +118,7 @@ impl<'a> Arena<'a> {
}
}

impl<'a> Drop for Arena<'a> {
impl Drop for Arena<'_> {
fn drop(&mut self) {
if self.bufs.is_empty() {
// nothing to do
Expand Down
10 changes: 5 additions & 5 deletions src/io/mmap/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct Stream<'a> {
active: bool,
}

impl<'a> Stream<'a> {
impl Stream<'_> {
/// Returns a stream for frame capturing
///
/// # Arguments
Expand Down Expand Up @@ -89,7 +89,7 @@ impl<'a> Stream<'a> {
}
}

impl<'a> Drop for Stream<'a> {
impl Drop for Stream<'_> {
fn drop(&mut self) {
if let Err(e) = self.stop() {
if let Some(code) = e.raw_os_error() {
Expand All @@ -107,7 +107,7 @@ impl<'a> Drop for Stream<'a> {
}
}

impl<'a> StreamTrait for Stream<'a> {
impl StreamTrait for Stream<'_> {
type Item = [u8];

fn start(&mut self) -> io::Result<()> {
Expand Down Expand Up @@ -139,7 +139,7 @@ impl<'a> StreamTrait for Stream<'a> {
}
}

impl<'a, 'b> CaptureStream<'b> for Stream<'a> {
impl<'b> CaptureStream<'b> for Stream<'_> {
fn queue(&mut self, index: usize) -> io::Result<()> {
let mut v4l2_buf = v4l2_buffer {
index: index as u32,
Expand Down Expand Up @@ -209,7 +209,7 @@ impl<'a, 'b> CaptureStream<'b> for Stream<'a> {
}
}

impl<'a, 'b> OutputStream<'b> for Stream<'a> {
impl<'b> OutputStream<'b> for Stream<'_> {
fn queue(&mut self, index: usize) -> io::Result<()> {
let mut v4l2_buf = v4l2_buffer {
index: index as u32,
Expand Down
6 changes: 2 additions & 4 deletions src/video/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ macro_rules! impl_enum_frameintervals {
if ret.is_err() {
if v4l2_struct.index == 0 {
return Err(ret.err().unwrap());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No conversion here, can we use if let Err(e) to get rid of the unwrap()?

} else {
return Ok(frameintervals);
}
return Ok(frameintervals);
}

if let Ok(frame_interval) = FrameInterval::try_from(v4l2_struct) {
Comment on lines 28 to 34
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this what you were thinking about? It's a little scary in the macro, but cargo check is happy!

Suggested change
if v4l2_struct.index == 0 {
return Err(ret.err().unwrap());
} else {
return Ok(frameintervals);
}
return Ok(frameintervals);
}
if let Ok(frame_interval) = FrameInterval::try_from(v4l2_struct) {
if let Err(e) = ret {
if v4l2_struct.index == 0 {
return Err(e);
}
return Ok(frameintervals);
}
if let Ok(frame_interval) = FrameInterval::try_from(v4l2_struct) {

Expand Down Expand Up @@ -64,9 +63,8 @@ macro_rules! impl_enum_framesizes {
if ret.is_err() {
if v4l2_struct.index == 0 {
return Err(ret.err().unwrap());
} else {
return Ok(framesizes);
}
return Ok(framesizes);
}

if let Ok(frame_size) = FrameSize::try_from(v4l2_struct) {
Expand Down