Skip to content

Commit

Permalink
chore(rust): Make rust clippy happy (#1678)
Browse files Browse the repository at this point in the history
## 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 #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 <github@xuanwo.io>
Co-authored-by: Ruihang Xia <waynestxia@gmail.com>
  • Loading branch information
Xuanwo and waynexia committed Jun 7, 2024
1 parent 257564f commit a621b05
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 45 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion ci/run_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 7 additions & 3 deletions rust/fury/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
16 changes: 6 additions & 10 deletions rust/fury/src/deserializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
Expand Down Expand Up @@ -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();

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion rust/fury/src/row/bit_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions rust/fury/src/row/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

mod bit_util;
mod reader;
#[allow(clippy::module_inception)]
mod row;
mod writer;

Expand Down
20 changes: 10 additions & 10 deletions rust/fury/src/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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
Expand Down
38 changes: 19 additions & 19 deletions rust/fury/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -246,27 +246,27 @@ 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 {
type Error = Error;

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 }),
}
}
Expand Down

0 comments on commit a621b05

Please sign in to comment.