Browse Source

Rename RingBuffer::{dequeue_mut→dequeue}, remove RingBuffer::dequeue.

There's nothing dequeue can do that dequeue_mut cannot.
whitequark 7 năm trước cách đây
mục cha
commit
f31f7240be
2 tập tin đã thay đổi với 2 bổ sung15 xóa
  1. 1 1
      src/socket/raw.rs
  2. 1 14
      src/storage/ring_buffer.rs

+ 1 - 1
src/socket/raw.rs

@@ -176,7 +176,7 @@ impl<'a, 'b> RawSocket<'a, 'b> {
     pub(crate) fn dispatch<F, R>(&mut self, _timestamp: u64, _limits: &DeviceLimits,
                                  emit: &mut F) -> Result<R, Error>
             where F: FnMut(&IpRepr, &IpPayload) -> Result<R, Error> {
-        let mut packet_buf = self.tx_buffer.dequeue_mut().map_err(|()| Error::Exhausted)?;
+        let mut packet_buf = self.tx_buffer.dequeue().map_err(|()| Error::Exhausted)?;
         net_trace!("[{}]:{}:{}: sending {} octets",
                    self.debug_id, self.ip_version, self.ip_protocol,
                    packet_buf.size);

+ 1 - 14
src/storage/ring_buffer.rs

@@ -59,22 +59,9 @@ impl<'a, T: 'a> RingBuffer<'a, T> {
         }
     }
 
-    /// Dequeue an element from the buffer, and return a pointer to it, or return
-    /// `Err(())` if the buffer is empty.
-    pub fn dequeue(&mut self) -> Result<&T, ()> {
-        if self.empty() {
-            Err(())
-        } else {
-            self.length -= 1;
-            let result = &self.storage[self.read_at];
-            self.read_at = self.incr(self.read_at);
-            Ok(result)
-        }
-    }
-
     /// Dequeue an element from the buffer, and return a mutable reference to it, or return
     /// `Err(())` if the buffer is empty.
-    pub fn dequeue_mut(&mut self) -> Result<&mut T, ()> {
+    pub fn dequeue(&mut self) -> Result<&mut T, ()> {
         if self.empty() {
             Err(())
         } else {