RingBuffer::{empty,full}→is_{empty,full}.
Query methods in Rust conventionally start with the "is" prefix.
This commit is contained in:
parent
5ffce2c1a6
commit
e8788be3a0
|
@ -107,13 +107,13 @@ impl<'a, 'b> RawSocket<'a, 'b> {
|
|||
/// Check whether the transmit buffer is full.
|
||||
#[inline]
|
||||
pub fn can_send(&self) -> bool {
|
||||
!self.tx_buffer.full()
|
||||
!self.tx_buffer.is_full()
|
||||
}
|
||||
|
||||
/// Check whether the receive buffer is not empty.
|
||||
#[inline]
|
||||
pub fn can_recv(&self) -> bool {
|
||||
!self.rx_buffer.empty()
|
||||
!self.rx_buffer.is_empty()
|
||||
}
|
||||
|
||||
/// Enqueue a packet to send, and return a pointer to its payload.
|
||||
|
@ -228,7 +228,7 @@ impl<'a, 'b> RawSocket<'a, 'b> {
|
|||
}
|
||||
|
||||
pub(crate) fn poll_at(&self) -> Option<u64> {
|
||||
if self.tx_buffer.empty() {
|
||||
if self.tx_buffer.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(0)
|
||||
|
|
|
@ -452,7 +452,7 @@ impl<'a> TcpSocket<'a> {
|
|||
pub fn can_send(&self) -> bool {
|
||||
if !self.may_send() { return false }
|
||||
|
||||
!self.tx_buffer.full()
|
||||
!self.tx_buffer.is_full()
|
||||
}
|
||||
|
||||
/// Check whether the receive half of the full-duplex connection buffer is open
|
||||
|
@ -461,7 +461,7 @@ impl<'a> TcpSocket<'a> {
|
|||
pub fn can_recv(&self) -> bool {
|
||||
if !self.may_recv() { return false }
|
||||
|
||||
!self.rx_buffer.empty()
|
||||
!self.rx_buffer.is_empty()
|
||||
}
|
||||
|
||||
/// Enqueue a sequence of octets to be sent, and return a pointer to it.
|
||||
|
@ -1203,7 +1203,7 @@ impl<'a> TcpSocket<'a> {
|
|||
|
||||
pub(crate) fn poll_at(&self) -> Option<u64> {
|
||||
self.timer.poll_at().or_else(|| {
|
||||
if self.tx_buffer.empty() {
|
||||
if self.tx_buffer.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(0)
|
||||
|
|
|
@ -121,13 +121,13 @@ impl<'a, 'b> UdpSocket<'a, 'b> {
|
|||
/// Check whether the transmit buffer is full.
|
||||
#[inline]
|
||||
pub fn can_send(&self) -> bool {
|
||||
!self.tx_buffer.full()
|
||||
!self.tx_buffer.is_full()
|
||||
}
|
||||
|
||||
/// Check whether the receive buffer is not empty.
|
||||
#[inline]
|
||||
pub fn can_recv(&self) -> bool {
|
||||
!self.rx_buffer.empty()
|
||||
!self.rx_buffer.is_empty()
|
||||
}
|
||||
|
||||
/// Enqueue a packet to be sent to a given remote endpoint, and return a pointer
|
||||
|
@ -224,7 +224,7 @@ impl<'a, 'b> UdpSocket<'a, 'b> {
|
|||
}
|
||||
|
||||
pub(crate) fn poll_at(&self) -> Option<u64> {
|
||||
if self.tx_buffer.empty() {
|
||||
if self.tx_buffer.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(0)
|
||||
|
|
|
@ -70,12 +70,12 @@ impl<'a, T: 'a> RingBuffer<'a, T> {
|
|||
}
|
||||
|
||||
/// Query whether the buffer is empty.
|
||||
pub fn empty(&self) -> bool {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.len() == 0
|
||||
}
|
||||
|
||||
/// Query whether the buffer is full.
|
||||
pub fn full(&self) -> bool {
|
||||
pub fn is_full(&self) -> bool {
|
||||
self.window() == 0
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ impl<'a, T: 'a> RingBuffer<'a, T> {
|
|||
/// returns successfully, or return `Err(Error::Exhausted)` if the buffer is full.
|
||||
pub fn enqueue_one_with<'b, R, F>(&'b mut self, f: F) -> Result<R>
|
||||
where F: FnOnce(&'b mut T) -> Result<R> {
|
||||
if self.full() { return Err(Error::Exhausted) }
|
||||
if self.is_full() { return Err(Error::Exhausted) }
|
||||
|
||||
let index = (self.read_at + self.length) % self.capacity();
|
||||
match f(&mut self.storage[index]) {
|
||||
|
@ -111,7 +111,7 @@ impl<'a, T: 'a> RingBuffer<'a, T> {
|
|||
/// returns successfully, or return `Err(Error::Exhausted)` if the buffer is empty.
|
||||
pub fn dequeue_one_with<'b, R, F>(&'b mut self, f: F) -> Result<R>
|
||||
where F: FnOnce(&'b mut T) -> Result<R> {
|
||||
if self.empty() { return Err(Error::Exhausted) }
|
||||
if self.is_empty() { return Err(Error::Exhausted) }
|
||||
|
||||
let next_at = (self.read_at + 1) % self.capacity();
|
||||
match f(&mut self.storage[self.read_at]) {
|
||||
|
@ -280,22 +280,22 @@ mod test {
|
|||
#[test]
|
||||
fn test_buffer_length_changes() {
|
||||
let mut ring = RingBuffer::new(vec![0; 2]);
|
||||
assert!(ring.empty());
|
||||
assert!(!ring.full());
|
||||
assert!(ring.is_empty());
|
||||
assert!(!ring.is_full());
|
||||
assert_eq!(ring.len(), 0);
|
||||
assert_eq!(ring.capacity(), 2);
|
||||
assert_eq!(ring.window(), 2);
|
||||
|
||||
ring.length = 1;
|
||||
assert!(!ring.empty());
|
||||
assert!(!ring.full());
|
||||
assert!(!ring.is_empty());
|
||||
assert!(!ring.is_full());
|
||||
assert_eq!(ring.len(), 1);
|
||||
assert_eq!(ring.capacity(), 2);
|
||||
assert_eq!(ring.window(), 1);
|
||||
|
||||
ring.length = 2;
|
||||
assert!(!ring.empty());
|
||||
assert!(ring.full());
|
||||
assert!(!ring.is_empty());
|
||||
assert!(ring.is_full());
|
||||
assert_eq!(ring.len(), 2);
|
||||
assert_eq!(ring.capacity(), 2);
|
||||
assert_eq!(ring.window(), 0);
|
||||
|
@ -308,24 +308,24 @@ mod test {
|
|||
Err(Error::Exhausted));
|
||||
|
||||
ring.enqueue_one_with(|e| Ok(e)).unwrap();
|
||||
assert!(!ring.empty());
|
||||
assert!(!ring.full());
|
||||
assert!(!ring.is_empty());
|
||||
assert!(!ring.is_full());
|
||||
|
||||
for i in 1..5 {
|
||||
ring.enqueue_one_with(|e| Ok(*e = i)).unwrap();
|
||||
assert!(!ring.empty());
|
||||
assert!(!ring.is_empty());
|
||||
}
|
||||
assert!(ring.full());
|
||||
assert!(ring.is_full());
|
||||
assert_eq!(ring.enqueue_one_with(|_| unreachable!()) as Result<()>,
|
||||
Err(Error::Exhausted));
|
||||
|
||||
for i in 0..5 {
|
||||
assert_eq!(ring.dequeue_one_with(|e| Ok(*e)).unwrap(), i);
|
||||
assert!(!ring.full());
|
||||
assert!(!ring.is_full());
|
||||
}
|
||||
assert_eq!(ring.dequeue_one_with(|_| unreachable!()) as Result<()>,
|
||||
Err(Error::Exhausted));
|
||||
assert!(ring.empty());
|
||||
assert!(ring.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -334,22 +334,22 @@ mod test {
|
|||
assert_eq!(ring.dequeue_one(), Err(Error::Exhausted));
|
||||
|
||||
ring.enqueue_one().unwrap();
|
||||
assert!(!ring.empty());
|
||||
assert!(!ring.full());
|
||||
assert!(!ring.is_empty());
|
||||
assert!(!ring.is_full());
|
||||
|
||||
for i in 1..5 {
|
||||
*ring.enqueue_one().unwrap() = i;
|
||||
assert!(!ring.empty());
|
||||
assert!(!ring.is_empty());
|
||||
}
|
||||
assert!(ring.full());
|
||||
assert!(ring.is_full());
|
||||
assert_eq!(ring.enqueue_one(), Err(Error::Exhausted));
|
||||
|
||||
for i in 0..5 {
|
||||
assert_eq!(*ring.dequeue_one().unwrap(), i);
|
||||
assert!(!ring.full());
|
||||
assert!(!ring.is_full());
|
||||
}
|
||||
assert_eq!(ring.dequeue_one(), Err(Error::Exhausted));
|
||||
assert!(ring.empty());
|
||||
assert!(ring.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue