Quellcode durchsuchen

Clean up some type variable names and trait bounds. NFC.

whitequark vor 7 Jahren
Ursprung
Commit
97499ac280
2 geänderte Dateien mit 31 neuen und 35 gelöschten Zeilen
  1. 14 16
      src/phy/fault_injector.rs
  2. 17 19
      src/phy/tracer.rs

+ 14 - 16
src/phy/fault_injector.rs

@@ -108,15 +108,15 @@ impl State {
 /// adverse network conditions (such as random packet loss or corruption), or software
 /// or hardware limitations (such as a limited number or size of usable network buffers).
 #[derive(Debug)]
-pub struct FaultInjector<T: Device> {
-    lower:  T,
+pub struct FaultInjector<D: Device> {
+    lower:  D,
     state:  State,
     config: Config
 }
 
-impl<T: Device> FaultInjector<T> {
+impl<D: Device> FaultInjector<D> {
     /// Create a fault injector device, using the given random number generator seed.
-    pub fn new(lower: T, seed: u32) -> FaultInjector<T> {
+    pub fn new(lower: D, seed: u32) -> FaultInjector<D> {
         #[cfg(feature = "std")]
         let state = State {
             rng_seed:    seed,
@@ -136,7 +136,7 @@ impl<T: Device> FaultInjector<T> {
     }
 
     /// Return the underlying device, consuming the fault injector.
-    pub fn into_lower(self) -> T {
+    pub fn into_lower(self) -> D {
         self.lower
     }
 
@@ -216,10 +216,10 @@ impl<T: Device> FaultInjector<T> {
     }
 }
 
-impl<T: Device> Device for FaultInjector<T>
-        where T::RxBuffer: AsMut<[u8]> {
-    type RxBuffer = T::RxBuffer;
-    type TxBuffer = TxBuffer<T::TxBuffer>;
+impl<D: Device> Device for FaultInjector<D>
+        where D::RxBuffer: AsMut<[u8]> {
+    type RxBuffer = D::RxBuffer;
+    type TxBuffer = TxBuffer<D::TxBuffer>;
 
     fn limits(&self) -> DeviceLimits {
         let mut limits = self.lower.limits();
@@ -275,16 +275,15 @@ impl<T: Device> Device for FaultInjector<T>
 }
 
 #[doc(hidden)]
-pub struct TxBuffer<T: AsRef<[u8]> + AsMut<[u8]>> {
+pub struct TxBuffer<B: AsRef<[u8]> + AsMut<[u8]>> {
     state:  State,
     config: Config,
-    buffer: Option<T>,
+    buffer: Option<B>,
     junk:   [u8; MTU],
     length: usize
 }
 
-impl<T: AsRef<[u8]> + AsMut<[u8]>> AsRef<[u8]>
-        for TxBuffer<T> {
+impl<B: AsRef<[u8]> + AsMut<[u8]>> AsRef<[u8]> for TxBuffer<B> {
     fn as_ref(&self) -> &[u8] {
         match self.buffer {
             Some(ref buf) => buf.as_ref(),
@@ -293,8 +292,7 @@ impl<T: AsRef<[u8]> + AsMut<[u8]>> AsRef<[u8]>
     }
 }
 
-impl<T: AsRef<[u8]> + AsMut<[u8]>> AsMut<[u8]>
-        for TxBuffer<T> {
+impl<B: AsRef<[u8]> + AsMut<[u8]>> AsMut<[u8]> for TxBuffer<B> {
     fn as_mut(&mut self) -> &mut [u8] {
         match self.buffer {
             Some(ref mut buf) => buf.as_mut(),
@@ -303,7 +301,7 @@ impl<T: AsRef<[u8]> + AsMut<[u8]>> AsMut<[u8]>
     }
 }
 
-impl<T: AsRef<[u8]> + AsMut<[u8]>> Drop for TxBuffer<T> {
+impl<B: AsRef<[u8]> + AsMut<[u8]>> Drop for TxBuffer<B> {
     fn drop(&mut self) {
         match self.buffer {
             Some(ref mut buf) => {

+ 17 - 19
src/phy/tracer.rs

@@ -7,14 +7,14 @@ use super::{DeviceLimits, Device};
 /// A tracer is a device that pretty prints all packets traversing it
 /// using the provided writer function, and then passes them to another
 /// device.
-pub struct Tracer<T: Device, U: PrettyPrint> {
-    lower:     T,
-    writer:    fn(u64, PrettyPrinter<U>)
+pub struct Tracer<D: Device, P: PrettyPrint> {
+    lower:     D,
+    writer:    fn(u64, PrettyPrinter<P>)
 }
 
-impl<T: Device, U: PrettyPrint> Tracer<T, U> {
+impl<D: Device, P: PrettyPrint> Tracer<D, P> {
     /// Create a tracer device.
-    pub fn new(lower: T, writer: fn(timestamp: u64, printer: PrettyPrinter<U>)) -> Tracer<T, U> {
+    pub fn new(lower: D, writer: fn(timestamp: u64, printer: PrettyPrinter<P>)) -> Tracer<D, P> {
         Tracer {
             lower:   lower,
             writer:  writer
@@ -22,20 +22,20 @@ impl<T: Device, U: PrettyPrint> Tracer<T, U> {
     }
 
     /// Return the underlying device, consuming the tracer.
-    pub fn into_lower(self) -> T {
+    pub fn into_lower(self) -> D {
         self.lower
     }
 }
 
-impl<T: Device, U: PrettyPrint> Device for Tracer<T, U> {
-    type RxBuffer = T::RxBuffer;
-    type TxBuffer = TxBuffer<T::TxBuffer, U>;
+impl<D: Device, P: PrettyPrint> Device for Tracer<D, P> {
+    type RxBuffer = D::RxBuffer;
+    type TxBuffer = TxBuffer<D::TxBuffer, P>;
 
     fn limits(&self) -> DeviceLimits { self.lower.limits() }
 
     fn receive(&mut self, timestamp: u64) -> Result<Self::RxBuffer, Error> {
         let buffer = self.lower.receive(timestamp)?;
-        (self.writer)(timestamp, PrettyPrinter::<U>::new("<- ", &buffer));
+        (self.writer)(timestamp, PrettyPrinter::<P>::new("<- ", &buffer));
         Ok(buffer)
     }
 
@@ -46,24 +46,22 @@ impl<T: Device, U: PrettyPrint> Device for Tracer<T, U> {
 }
 
 #[doc(hidden)]
-pub struct TxBuffer<T: AsRef<[u8]>, U: PrettyPrint> {
-    buffer:    T,
+pub struct TxBuffer<B: AsRef<[u8]> + AsMut<[u8]>, P: PrettyPrint> {
+    buffer:    B,
     timestamp: u64,
-    writer:    fn(u64, PrettyPrinter<U>)
+    writer:    fn(u64, PrettyPrinter<P>)
 }
 
-impl<T: AsRef<[u8]>, U: PrettyPrint> AsRef<[u8]>
-        for TxBuffer<T, U> {
+impl<B: AsRef<[u8]> + AsMut<[u8]>, P: PrettyPrint> AsRef<[u8]> for TxBuffer<B, P> {
     fn as_ref(&self) -> &[u8] { self.buffer.as_ref() }
 }
 
-impl<T: AsRef<[u8]> + AsMut<[u8]>, U: PrettyPrint> AsMut<[u8]>
-        for TxBuffer<T, U> {
+impl<B: AsRef<[u8]> + AsMut<[u8]>, P: PrettyPrint> AsMut<[u8]> for TxBuffer<B, P> {
     fn as_mut(&mut self) -> &mut [u8] { self.buffer.as_mut() }
 }
 
-impl<T: AsRef<[u8]>, U: PrettyPrint> Drop for TxBuffer<T, U> {
+impl<B: AsRef<[u8]> + AsMut<[u8]>, P: PrettyPrint> Drop for TxBuffer<B, P> {
     fn drop(&mut self) {
-        (self.writer)(self.timestamp, PrettyPrinter::<U>::new("-> ", &self.buffer));
+        (self.writer)(self.timestamp, PrettyPrinter::<P>::new("-> ", &self.buffer));
     }
 }