runningwater преди 2 години
родител
ревизия
f2d1a94f2f
променени са 5 файла, в които са добавени 21 реда и са изтрити 6 реда
  1. 4 0
      src/fifth.rs
  2. 5 1
      src/fourth.rs
  3. 1 0
      src/lib.rs
  4. 5 5
      src/second.rs
  5. 6 0
      src/third.rs

+ 4 - 0
src/fifth.rs

@@ -0,0 +1,4 @@
+/* Copyright (C) 2023-2023 Hangzhou HSH Co. Ltd.
+ * All right reserved.*/
+/// An OK Unsafe Queue
+pub struct List {}

+ 5 - 1
src/fourth.rs

@@ -161,7 +161,11 @@ impl<T> Drop for List<T> {
         while self.pop_front().is_some() {}
     }
 }
-
+impl<T> Default for List<T> {
+    fn default() -> Self {
+        Self::new()
+    }
+}
 pub struct IntoIter<T>(List<T>);
 
 impl<T> List<T> {

+ 1 - 0
src/lib.rs

@@ -1,3 +1,4 @@
+pub mod fifth;
 pub mod first;
 pub mod fourth;
 pub mod second;

+ 5 - 5
src/second.rs

@@ -35,7 +35,7 @@ impl<T> List<T> {
 }
 impl<T> Default for List<T> {
     fn default() -> Self {
-        Self { head: None }
+        Self::new()
     }
 }
 impl<T> Drop for List<T> {
@@ -74,7 +74,7 @@ pub struct Iter<'a, T> {
     next: Option<&'a Node<T>>,
 }
 impl<T> List<T> {
-    pub fn iter<'a>(&'a self) -> Iter<'a, T> {
+    pub fn iter(&self) -> Iter<'_, T> {
         Iter {
             next: self.head.as_deref(),
         }
@@ -83,7 +83,7 @@ impl<T> List<T> {
 impl<'a, T> Iterator for Iter<'a, T> {
     type Item = &'a T;
 
-    fn next<'b>(&'b mut self) -> Option<Self::Item> {
+    fn next(&mut self) -> Option<Self::Item> {
         self.next.map(|node| {
             self.next = node.next.as_deref();
             &node.elem
@@ -94,7 +94,7 @@ pub struct IterMut<'a, T> {
     next: Option<&'a mut Node<T>>,
 }
 impl<T> List<T> {
-    pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T> {
+    pub fn iter_mut(&mut self) -> IterMut<'_, T> {
         IterMut {
             next: self.head.as_deref_mut(),
         }
@@ -103,7 +103,7 @@ impl<T> List<T> {
 impl<'a, T> Iterator for IterMut<'a, T> {
     type Item = &'a mut T;
 
-    fn next<'b>(&'b mut self) -> Option<Self::Item> {
+    fn next(&mut self) -> Option<Self::Item> {
         self.next.take().map(|node| {
             self.next = node.next.as_deref_mut();
             &mut node.elem

+ 6 - 0
src/third.rs

@@ -42,6 +42,12 @@ impl<T> Drop for List<T> {
         }
     }
 }
+
+impl<T> Default for List<T> {
+    fn default() -> Self {
+        Self::new()
+    }
+}
 pub struct Iter<'a, T> {
     next: Option<&'a Node<T>>,
 }