From e8788be3a0cb2e6dc4d91b47f2968863e49a5d43 Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 8 Sep 2017 23:23:40 +0000 Subject: [PATCH] =?UTF-8?q?RingBuffer::{empty,full}=E2=86=92is=5F{empty,fu?= =?UTF-8?q?ll}.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Query methods in Rust conventionally start with the "is" prefix. --- src/socket/raw.rs | 6 +++--- src/socket/tcp.rs | 6 +++--- src/socket/udp.rs | 6 +++--- src/storage/ring_buffer.rs | 44 +++++++++++++++++++------------------- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/socket/raw.rs b/src/socket/raw.rs index e2fe01f..6f22fc8 100644 --- a/src/socket/raw.rs +++ b/src/socket/raw.rs @@ -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 { - if self.tx_buffer.empty() { + if self.tx_buffer.is_empty() { None } else { Some(0) diff --git a/src/socket/tcp.rs b/src/socket/tcp.rs index 39e94eb..bef7967 100644 --- a/src/socket/tcp.rs +++ b/src/socket/tcp.rs @@ -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 { self.timer.poll_at().or_else(|| { - if self.tx_buffer.empty() { + if self.tx_buffer.is_empty() { None } else { Some(0) diff --git a/src/socket/udp.rs b/src/socket/udp.rs index 8bc353a..0f57a0c 100644 --- a/src/socket/udp.rs +++ b/src/socket/udp.rs @@ -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 { - if self.tx_buffer.empty() { + if self.tx_buffer.is_empty() { None } else { Some(0) diff --git a/src/storage/ring_buffer.rs b/src/storage/ring_buffer.rs index af1277c..881c8fc 100644 --- a/src/storage/ring_buffer.rs +++ b/src/storage/ring_buffer.rs @@ -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 where F: FnOnce(&'b mut T) -> Result { - 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 where F: FnOnce(&'b mut T) -> Result { - 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]