Browse Source

Apply clippy lints

$ rustup component add clippy
$ cargo clippy
pull/10/head
Andreas Linz 2 years ago
parent
commit
01454365fd
Signed by: alinz GPG Key ID: 9BF39809C9DA580C
1 changed files with 14 additions and 13 deletions
  1. +14
    -13
      src/lib.rs

+ 14
- 13
src/lib.rs View File

@ -106,9 +106,9 @@ pub enum RbError {
}
impl fmt::Display for RbError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
&RbError::Full => write!(f, "No free slots in the buffer"),
&RbError::Empty => write!(f, "Buffer is empty"),
match *self {
RbError::Full => write!(f, "No free slots in the buffer"),
RbError::Empty => write!(f, "Buffer is empty"),
}
}
}
@ -238,9 +238,10 @@ impl RbInspector for Inspector {
fn slots_free(&self) -> usize {
let wr_pos = self.write_pos.load(Ordering::Relaxed);
let re_pos = self.read_pos.load(Ordering::Relaxed);
match wr_pos < re_pos {
true => re_pos - wr_pos - 1,
false => self.capacity() - wr_pos + re_pos,
if wr_pos < re_pos {
re_pos - wr_pos - 1
} else {
self.capacity() - wr_pos + re_pos
}
}
@ -268,7 +269,7 @@ pub struct Consumer {
impl<T: Clone + Copy> RbProducer<T> for Producer<T> {
fn write(&self, data: &[T]) -> Result<usize> {
if data.len() == 0 {
if data.is_empty() {
return Ok(0);
}
if self.inspector.is_full() {
@ -291,11 +292,11 @@ impl RbProducer for Producer {
.store((wr_pos + cnt) % buf_len, Ordering::Relaxed);
self.data_available.notify_one();
return Ok(cnt);
Ok(cnt)
}
fn write_blocking(&self, data: &[T]) -> Option<usize> {
if data.len() == 0 {
if data.is_empty() {
return None;
}
let guard = self.buf.lock().unwrap();
@ -321,7 +322,7 @@ impl RbProducer for Producer {
.store((wr_pos + cnt) % buf_len, Ordering::Relaxed);
self.data_available.notify_one();
return Some(cnt);
Some(cnt)
}
}
@ -353,7 +354,7 @@ impl RbConsumer for Consumer {
}
fn get(&self, data: &mut [T]) -> Result<usize> {
if data.len() == 0 {
if data.is_empty() {
return Ok(0);
}
if self.inspector.is_empty() {
@ -376,7 +377,7 @@ impl RbConsumer for Consumer {
}
fn read(&self, data: &mut [T]) -> Result<usize> {
if data.len() == 0 {
if data.is_empty() {
return Ok(0);
}
if self.inspector.is_empty() {
@ -404,7 +405,7 @@ impl RbConsumer for Consumer {
}
fn read_blocking(&self, data: &mut [T]) -> Option<usize> {
if data.len() == 0 {
if data.is_empty() {
return None;
}
let guard = self.buf.lock().unwrap();

Loading…
Cancel
Save