Skip to content

Commit

Permalink
chore: add lints to protobuf
Browse files Browse the repository at this point in the history
Lior banned `as` repo-wide, unless absolutely necessary.

Changes: use try_from instead of relying on implicit truncation due of
`u128 as u64`.
  • Loading branch information
Gilad Chase committed Nov 7, 2024
1 parent 2b71c91 commit 3739dda
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions crates/papyrus_protobuf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ protoc-prebuilt.workspace = true
[package.metadata.cargo-machete]
# The `rand` and `rand_chacha` crates are used in the `testing` feature, which is optional.
ignored = ["rand", "rand_chacha"]

[lints]
workspace = true
6 changes: 5 additions & 1 deletion crates/papyrus_protobuf/src/converters/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ impl From<starknet_api::core::ContractAddress> for protobuf::Address {

impl From<u128> for protobuf::Uint128 {
fn from(value: u128) -> Self {
Self { high: (value >> 64) as u64, low: value as u64 }
Self {
high: u64::try_from(value >> 64).expect("64-bit shift of u128 is a u64."),
low: u64::try_from(value & u128::from(u64::MAX))
.expect("Bottom 64 bits of u128 are a u64."),
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/papyrus_protobuf/src/converters/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl From<Vote> for protobuf::Vote {
};

protobuf::Vote {
vote_type: vote_type as i32,
vote_type: i32::from(vote_type),
height: value.height,
round: value.round,
block_hash: value.block_hash.map(|hash| hash.0.into()),
Expand Down

0 comments on commit 3739dda

Please sign in to comment.