Skip to content

Commit

Permalink
cargo 1.83 updates (#905)
Browse files Browse the repository at this point in the history
* elide unneeded lifetime

* clippy type complexity use alias

* clippy use div_ceil

* clippy empty line after attribute
  • Loading branch information
michaeldjeffrey authored Dec 3, 2024
1 parent 7cb6add commit cfa9afb
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion iot_config/src/lora_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ impl<'de, const WIDTH: usize> Deserialize<'de> for LoraField<WIDTH> {
{
struct LoraFieldVisitor<const IN_WIDTH: usize>;

impl<'de, const IN_WIDTH: usize> serde::de::Visitor<'de> for LoraFieldVisitor<IN_WIDTH> {
impl<const IN_WIDTH: usize> serde::de::Visitor<'_> for LoraFieldVisitor<IN_WIDTH> {
type Value = LoraField<IN_WIDTH>;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion iot_packet_verifier/src/pending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl PendingTables for PgPool {
}

#[async_trait]
impl<'a> AddPendingBurn for &'_ mut Transaction<'a, Postgres> {
impl AddPendingBurn for &'_ mut Transaction<'_, Postgres> {
async fn add_burned_amount(
&mut self,
payer: &PublicKeyBinary,
Expand Down
15 changes: 13 additions & 2 deletions iot_packet_verifier/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ pub const BYTES_PER_DC: u64 = 24;

pub fn payload_size_to_dc(payload_size: u64) -> u64 {
let payload_size = payload_size.max(BYTES_PER_DC);
// Integer div/ceil from: https://stackoverflow.com/a/2745086
(payload_size + BYTES_PER_DC - 1) / BYTES_PER_DC
payload_size.div_ceil(BYTES_PER_DC)
}

#[async_trait]
Expand Down Expand Up @@ -391,3 +390,15 @@ impl<T: Send> PacketWriter<T> for &'_ mut Vec<T> {
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_payload_size_to_dc() {
assert_eq!(1, payload_size_to_dc(1));
assert_eq!(1, payload_size_to_dc(24));
assert_eq!(2, payload_size_to_dc(25));
}
}
1 change: 0 additions & 1 deletion iot_verifier/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use task_manager::TaskManager;
#[derive(Debug, clap::Parser)]
#[clap(version = env!("CARGO_PKG_VERSION"))]
#[clap(about = "Helium POC IOT Verifier")]

pub struct Cli {
/// Optional configuration file to use. If present the toml file at the
/// given path will be loaded. Environment variables can override the
Expand Down
14 changes: 8 additions & 6 deletions metrics/src/client_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,26 @@ where
ApiTimingLayer::new(histogram_name).with_filter(filter::filter_fn(|m| m.name() == SPAN_NAME))
}

pub trait ClientMetricTiming<A, B>: Sized + Instrument + FutureExt {
type InstrumentedInspectable<Fut, Func> = Instrumented<Inspect<Fut, Func>>;

pub trait ClientMetricTiming<T, E>: Sized + Instrument + FutureExt {
fn with_timing(
self,
name: &'static str,
) -> Instrumented<Inspect<Self, impl FnOnce(&Result<A, B>)>>
) -> InstrumentedInspectable<Self, impl FnOnce(&Result<T, E>)>
where
Self: Future<Output = Result<A, B>> + Sized;
Self: Future<Output = Result<T, E>> + Sized;
}

// Impl ClientMetricTiming for all futures that return a Result
impl<F, A, B> ClientMetricTiming<A, B> for F
impl<F, T, E> ClientMetricTiming<T, E> for F
where
F: Future<Output = Result<A, B>> + Sized,
F: Future<Output = Result<T, E>> + Sized,
{
fn with_timing(
self,
name: &'static str,
) -> Instrumented<Inspect<Self, impl FnOnce(&Result<A, B>)>> {
) -> InstrumentedInspectable<Self, impl FnOnce(&Result<T, E>)> {
// NOTE(mj): `tracing::info_span!(SPAN_NAME, {NAME_FIELD} = name, {RESULT_FIELD} = tracing::field::Empty);`
//
// Results in the error "format must be a string literal". Maybe one day
Expand Down
15 changes: 13 additions & 2 deletions mobile_packet_verifier/src/pending_burns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ const BYTES_PER_DC: u64 = 20_000;

fn bytes_to_dc(bytes: u64) -> u64 {
let bytes = bytes.max(BYTES_PER_DC);
// Integer div/ceil from: https://stackoverflow.com/a/2745086
(bytes + BYTES_PER_DC - 1) / BYTES_PER_DC
bytes.div_ceil(BYTES_PER_DC)
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_bytes_to_dc() {
assert_eq!(1, bytes_to_dc(1));
assert_eq!(1, bytes_to_dc(20_000));
assert_eq!(2, bytes_to_dc(20_001));
}
}

0 comments on commit cfa9afb

Please sign in to comment.