Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust/fory-core/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl<'a> Writer<'a> {

#[inline(always)]
pub fn write_sliint64(&mut self, value: i64) {
if value >= HALF_MIN_INT && value <= HALF_MAX_INT {
if (HALF_MIN_INT..=HALF_MAX_INT).contains(&value) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use this range instead of conditional?

Copy link
Contributor Author

@urlyy urlyy Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the lint error and hint I got:

$ cargo clippy --all-targets --all-features -- -D warnings

error: manual `RangeInclusive::contains` implementation                                                                                                                                                                            
   --> fory-core\src\buffer.rs:182:12
    |
182 |         if value >= HALF_MIN_INT && value <= HALF_MAX_INT {
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `(HALF_MIN_INT..=HALF_MAX_INT).contains(&value)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains
    = note: `-D clippy::manual-range-contains` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::manual_range_contains)]`

You can see detail at https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains

Maybe more Rust-idiomatic, but actually, I think the condition is still more intuitive.

let v = (value as i32) << 1;
self.bf.extend_from_slice(&v.to_le_bytes());
} else {
Expand Down
Loading