This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-fury.git


The following commit(s) were added to refs/heads/main by this push:
     new a621b05c chore(rust): Make rust clippy happy (#1678)
a621b05c is described below

commit a621b05c5de94a80ae9d767b6842a91ecbe7ad50
Author: Xuanwo <[email protected]>
AuthorDate: Fri Jun 7 13:47:13 2024 +0800

    chore(rust): Make rust clippy happy (#1678)
    
    ## What does this PR do?
    
    Make rust clippy happy.
    
    I fixed all clippy warning and change the CI settings to reject new
    warnings.
    
    
    ## Related issues
    
    - close https://github.com/apache/incubator-fury/issues/1676
    
    
    ## Does this PR introduce any user-facing change?
    
    - [ ] Does this PR introduce any public API change?
    - [ ] Does this PR introduce any binary protocol compatibility change?
    
    
    ## Benchmark
    
    None
    
    ---------
    
    Signed-off-by: Xuanwo <[email protected]>
    Co-authored-by: Ruihang Xia <[email protected]>
---
 .github/workflows/ci.yml      |  1 -
 ci/run_ci.py                  |  2 +-
 rust/fury/src/buffer.rs       | 10 +++++++---
 rust/fury/src/deserializer.rs | 16 ++++++----------
 rust/fury/src/row/bit_util.rs |  2 +-
 rust/fury/src/row/mod.rs      |  1 +
 rust/fury/src/serializer.rs   | 20 ++++++++++----------
 rust/fury/src/types.rs        | 38 +++++++++++++++++++-------------------
 8 files changed, 45 insertions(+), 45 deletions(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index c22abdea..d5e919a0 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -171,7 +171,6 @@ jobs:
         uses: actions/setup-python@v5
         with:
           python-version: 3.11
-      - uses: dtolnay/rust-toolchain@nightly
       - name: Run Rust CI
         run: python ./ci/run_ci.py rust
 
diff --git a/ci/run_ci.py b/ci/run_ci.py
index 05c9fc1e..7a477409 100644
--- a/ci/run_ci.py
+++ b/ci/run_ci.py
@@ -93,7 +93,7 @@ def _run_rust():
         "cargo doc --no-deps --document-private-items --all-features --open",
         "cargo fmt --all -- --check",
         "cargo fmt --all",
-        "cargo clippy --workspace --all-features --all-targets",
+        "cargo clippy --workspace --all-features --all-targets -- -D warnings",
         "cargo doc",
         "cargo build --all-features --all-targets",
         "cargo test",
diff --git a/rust/fury/src/buffer.rs b/rust/fury/src/buffer.rs
index fbee048b..2ebf66b9 100644
--- a/rust/fury/src/buffer.rs
+++ b/rust/fury/src/buffer.rs
@@ -32,6 +32,10 @@ impl Writer {
         self.bf.len()
     }
 
+    pub fn is_empty(&self) -> bool {
+        self.bf.is_empty()
+    }
+
     pub fn reserve(&mut self, additional: usize) {
         self.reserved += additional;
         if self.bf.capacity() < self.reserved {
@@ -163,7 +167,7 @@ impl<'bf> Reader<'bf> {
     pub fn i16(&mut self) -> i16 {
         let result = LittleEndian::read_i16(self.slice_after_cursor());
         self.move_next(2);
-        result as i16
+        result
     }
 
     pub fn u32(&mut self) -> u32 {
@@ -175,7 +179,7 @@ impl<'bf> Reader<'bf> {
     pub fn i32(&mut self) -> i32 {
         let result = LittleEndian::read_i32(self.slice_after_cursor());
         self.move_next(4);
-        result as i32
+        result
     }
 
     pub fn u64(&mut self) -> u64 {
@@ -187,7 +191,7 @@ impl<'bf> Reader<'bf> {
     pub fn i64(&mut self) -> i64 {
         let result = LittleEndian::read_i64(self.slice_after_cursor());
         self.move_next(8);
-        result as i64
+        result
     }
 
     pub fn f32(&mut self) -> f32 {
diff --git a/rust/fury/src/deserializer.rs b/rust/fury/src/deserializer.rs
index 764f5595..0ca8f343 100644
--- a/rust/fury/src/deserializer.rs
+++ b/rust/fury/src/deserializer.rs
@@ -53,9 +53,7 @@ where
         // ref flag
         let ref_flag = deserializer.reader.i8();
 
-        if ref_flag == (RefFlag::NotNullValueFlag as i8)
-            || ref_flag == (RefFlag::RefValueFlag as i8)
-        {
+        if ref_flag == (RefFlag::NotNullValue as i8) || ref_flag == 
(RefFlag::RefValue as i8) {
             // type_id
             let type_id = deserializer.reader.i16();
             let ty = if Self::is_vec() {
@@ -71,9 +69,9 @@ where
             } else {
                 Ok(Self::read(deserializer)?)
             }
-        } else if ref_flag == (RefFlag::NullFlag as i8) {
+        } else if ref_flag == (RefFlag::Null as i8) {
             Err(Error::Null)
-        } else if ref_flag == (RefFlag::RefFlag as i8) {
+        } else if ref_flag == (RefFlag::Ref as i8) {
             Err(Error::Ref)
         } else {
             Err(Error::BadRefFlag)
@@ -189,9 +187,7 @@ impl<T: Deserialize> Deserialize for Option<T> {
         // ref flag
         let ref_flag = deserializer.reader.i8();
 
-        if ref_flag == (RefFlag::NotNullValueFlag as i8)
-            || ref_flag == (RefFlag::RefValueFlag as i8)
-        {
+        if ref_flag == (RefFlag::NotNullValue as i8) || ref_flag == 
(RefFlag::RefValue as i8) {
             // type_id
             let type_id = deserializer.reader.i16();
 
@@ -203,9 +199,9 @@ impl<T: Deserialize> Deserialize for Option<T> {
             } else {
                 Ok(Self::read(deserializer)?)
             }
-        } else if ref_flag == (RefFlag::NullFlag as i8) {
+        } else if ref_flag == (RefFlag::Null as i8) {
             Ok(None)
-        } else if ref_flag == (RefFlag::RefFlag as i8) {
+        } else if ref_flag == (RefFlag::Ref as i8) {
             Err(Error::Ref)
         } else {
             Err(Error::BadRefFlag)
diff --git a/rust/fury/src/row/bit_util.rs b/rust/fury/src/row/bit_util.rs
index 87ac2609..bbb94e5f 100644
--- a/rust/fury/src/row/bit_util.rs
+++ b/rust/fury/src/row/bit_util.rs
@@ -18,5 +18,5 @@
 const WORD_SIZE: usize = 8;
 
 pub fn calculate_bitmap_width_in_bytes(num_fields: usize) -> usize {
-    return ((num_fields + 63) / 64) * WORD_SIZE;
+    ((num_fields + 63) / 64) * WORD_SIZE
 }
diff --git a/rust/fury/src/row/mod.rs b/rust/fury/src/row/mod.rs
index 07842fbd..6c6d66f0 100644
--- a/rust/fury/src/row/mod.rs
+++ b/rust/fury/src/row/mod.rs
@@ -17,6 +17,7 @@
 
 mod bit_util;
 mod reader;
+#[allow(clippy::module_inception)]
 mod row;
 mod writer;
 
diff --git a/rust/fury/src/serializer.rs b/rust/fury/src/serializer.rs
index f22c1636..231e672f 100644
--- a/rust/fury/src/serializer.rs
+++ b/rust/fury/src/serializer.rs
@@ -71,7 +71,7 @@ where
     /// Step 1: write the length of the Vec into the buffer.
     /// Step 2: reserve the fixed size of all the elements.
     /// Step 3: loop through the Vec and invoke the serialize function of each 
item.
-    fn write_vec(value: &Vec<Self>, serializer: &mut SerializerState) {
+    fn write_vec(value: &[Self], serializer: &mut SerializerState) {
         serializer.writer.var_int32(value.len() as i32);
         serializer
             .writer
@@ -94,7 +94,7 @@ where
     /// Step 2: invoke the write function to write the Rust object.
     fn serialize(&self, serializer: &mut SerializerState) {
         // ref flag
-        serializer.writer.i8(RefFlag::NotNullValueFlag as i8);
+        serializer.writer.i8(RefFlag::NotNullValue as i8);
         // type
         serializer.writer.i16(if Self::is_vec() {
             Self::vec_ty()
@@ -130,9 +130,9 @@ macro_rules! impl_num_serialize_and_pritimive_vec {
                 serializer.writer.$name(*self);
             }
 
-            fn write_vec(value: &Vec<Self>, serializer: &mut SerializerState) {
+            fn write_vec(value: &[Self], serializer: &mut SerializerState) {
                 serializer.writer.var_int32(value.len() as i32);
-                serializer.writer.bytes(to_u8_slice(value.as_slice()));
+                serializer.writer.bytes(to_u8_slice(value));
             }
 
             fn reserved_space() -> usize {
@@ -161,7 +161,7 @@ impl Serialize for String {
         serializer.writer.bytes(self.as_bytes());
     }
 
-    fn write_vec(value: &Vec<Self>, serializer: &mut SerializerState) {
+    fn write_vec(value: &[Self], serializer: &mut SerializerState) {
         serializer.writer.var_int32(value.len() as i32);
         serializer
             .writer
@@ -182,9 +182,9 @@ impl Serialize for bool {
         serializer.writer.u8(if *self { 1 } else { 0 });
     }
 
-    fn write_vec(value: &Vec<Self>, serializer: &mut SerializerState) {
+    fn write_vec(value: &[Self], serializer: &mut SerializerState) {
         serializer.writer.var_int32(value.len() as i32);
-        serializer.writer.bytes(to_u8_slice(value.as_slice()));
+        serializer.writer.bytes(to_u8_slice(value));
     }
 
     fn reserved_space() -> usize {
@@ -291,14 +291,14 @@ where
         match self {
             Some(v) => {
                 // ref flag
-                serializer.writer.i8(RefFlag::NotNullValueFlag as i8);
+                serializer.writer.i8(RefFlag::NotNullValue as i8);
                 // type
                 serializer.writer.i16(<Self as FuryMeta>::ty() as i16);
 
                 v.write(serializer);
             }
             None => {
-                serializer.writer.i8(RefFlag::NullFlag as i8);
+                serializer.writer.i8(RefFlag::Null as i8);
             }
         }
     }
@@ -349,7 +349,7 @@ impl<'de> SerializerState<'de> {
         bitmap |= config_flags::IS_LITTLE_ENDIAN_FLAG;
         bitmap |= config_flags::IS_CROSS_LANGUAGE_FLAG;
         self.writer.u8(bitmap);
-        self.writer.u8(Language::RUST as u8);
+        self.writer.u8(Language::Rust as u8);
         self.writer.skip(4); // native offset
         self.writer.skip(4); // native size
         self
diff --git a/rust/fury/src/types.rs b/rust/fury/src/types.rs
index 0224d7d8..7c4647d7 100644
--- a/rust/fury/src/types.rs
+++ b/rust/fury/src/types.rs
@@ -142,14 +142,14 @@ pub enum StringFlag {
 }
 
 pub enum RefFlag {
-    NullFlag = -3,
-    // RefFlag indicates that object is a not-null value.
+    Null = -3,
+    // Ref indicates that object is a not-null value.
     // We don't use another byte to indicate REF, so that we can save one byte.
-    RefFlag = -2,
+    Ref = -2,
     // NotNullValueFlag indicates that the object is a non-null value.
-    NotNullValueFlag = -1,
+    NotNullValue = -1,
     // RefValueFlag indicates that the object is a referencable and first read.
-    RefValueFlag = 0,
+    RefValue = 0,
 }
 
 #[derive(Clone, Copy, Debug, PartialEq)]
@@ -246,13 +246,13 @@ pub mod config_flags {
 
 #[derive(Debug, PartialEq)]
 pub enum Language {
-    XLANG = 0,
-    JAVA = 1,
-    PYTHON = 2,
-    CPP = 3,
-    GO = 4,
-    JAVASCRIPT = 5,
-    RUST = 6,
+    Xlang = 0,
+    Java = 1,
+    Python = 2,
+    Cpp = 3,
+    Go = 4,
+    Javascript = 5,
+    Rust = 6,
 }
 
 impl TryFrom<u8> for Language {
@@ -260,13 +260,13 @@ impl TryFrom<u8> for Language {
 
     fn try_from(num: u8) -> Result<Self, Error> {
         match num {
-            0 => Ok(Language::XLANG),
-            1 => Ok(Language::JAVA),
-            2 => Ok(Language::PYTHON),
-            3 => Ok(Language::CPP),
-            4 => Ok(Language::GO),
-            5 => Ok(Language::JAVASCRIPT),
-            6 => Ok(Language::RUST),
+            0 => Ok(Language::Xlang),
+            1 => Ok(Language::Java),
+            2 => Ok(Language::Python),
+            3 => Ok(Language::Cpp),
+            4 => Ok(Language::Go),
+            5 => Ok(Language::Javascript),
+            6 => Ok(Language::Rust),
             _ => Err(Error::UnsupportLanguageCode { code: num }),
         }
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to