فهرست منبع

Applied clippy fixes for newest vec methods

Steve Thielemann 2 ماه پیش
والد
کامیت
e72acc6a50
1فایلهای تغییر یافته به همراه9 افزوده شده و 27 حذف شده
  1. 9 27
      src/data.rs

+ 9 - 27
src/data.rs

@@ -572,19 +572,13 @@ impl Data {
         matches!(self, Self::Map(_))
     }
     pub fn push(&mut self, v: Data) {
-        match self {
-            Self::Vec(vec) => {
-                vec.push(v);
-            }
-            _ => (),
+        if let Self::Vec(vec) = self {
+            vec.push(v);
         }
     }
     pub fn insert(&mut self, k: String, v: Data) {
-        match self {
-            Self::Map(hm) => {
-                hm.insert(k, v);
-            }
-            _ => (),
+        if let Self::Map(hm) = self {
+            hm.insert(k, v);
         }
     }
     pub fn len(&self) -> usize {
@@ -623,10 +617,7 @@ impl Data {
         }
     }
     pub fn truncate(&mut self, len: usize) {
-        match self {
-            Self::Vec(v) => v.truncate(len),
-            _ => (),
-        }
+        if let Self::Vec(v) = self { v.truncate(len) }
     }
     pub fn remove(&mut self, index: usize) -> Data {
         match self {
@@ -656,10 +647,7 @@ impl Data {
         }
     }
     pub fn resize(&mut self, len: usize, value: Data) {
-        match self {
-            Self::Vec(v) => v.resize(len, value),
-            _ => (),
-        }
+        if let Self::Vec(v) = self { v.resize(len, value) }
     }
     pub fn first(&self) -> Option<&Data> {
         match self {
@@ -690,7 +678,7 @@ impl Data {
         I: SliceIndex<[Data]>,
     {
         match self {
-            Self::Vec(v) => v.get::<I>(index.into()),
+            Self::Vec(v) => v.get::<I>(index),
             _ => None,
         }
     }
@@ -704,16 +692,10 @@ impl Data {
         }
     }
     pub fn swap(&mut self, a: usize, b: usize) {
-        match self {
-            Self::Vec(v) => v.swap(a, b),
-            _ => (),
-        }
+        if let Self::Vec(v) = self { v.swap(a, b) }
     }
     pub fn reverse(&mut self) {
-        match self {
-            Self::Vec(v) => v.reverse(),
-            _ => (),
-        }
+        if let Self::Vec(v) = self { v.reverse() }
     }
     pub fn vec_iter(&self) -> Option<Iter<'_, Data>> {
         match self {