From 43cc1261cc61f89ed8149f1fe103fd7fcc80412b Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 7 Oct 2024 11:08:20 +0200 Subject: [PATCH] Add `rust-version = 1.81` and fmt toml files and imports. --- .cargo/config.toml | 4 ++-- cli/Cargo.toml | 9 +++++++-- cli/src/cli.rs | 5 ++--- clippy.toml | 12 ++++++------ deny.toml | 2 +- ocpi-tariffs/Cargo.toml | 4 +++- ocpi-tariffs/src/ocpi/v211/cdr.rs | 16 ++++++++-------- ocpi-tariffs/src/ocpi/v211/tariff.rs | 16 ++++++++-------- ocpi-tariffs/src/ocpi/v221/cdr.rs | 14 +++++++------- ocpi-tariffs/src/ocpi/v221/tariff.rs | 13 +++++++------ ocpi-tariffs/src/pricer.rs | 10 +++++----- ocpi-tariffs/src/restriction.rs | 10 ++++++---- ocpi-tariffs/src/session.rs | 6 +++--- ocpi-tariffs/src/tariff.rs | 15 ++++++++------- ocpi-tariffs/src/types/money.rs | 3 ++- ocpi-tariffs/src/types/time.rs | 6 ++---- ocpi-tariffs/tests/integration.rs | 4 ++-- 17 files changed, 79 insertions(+), 70 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index fabd056..238ad24 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,6 +1,6 @@ [build] target-dir = "target" rustdocflags = [ - "-Arustdoc::private_intra_doc_links", - "-Drustdoc::broken_intra_doc_links", + "-Arustdoc::private_intra_doc_links", + "-Drustdoc::broken_intra_doc_links", ] diff --git a/cli/Cargo.toml b/cli/Cargo.toml index b3191fa..42828d2 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -13,10 +13,15 @@ path = "src/main.rs" [dependencies] chrono-tz.workspace = true -chrono = { version = "0.4.38", default-features = false, features = ["alloc", "serde"] } +chrono = { version = "0.4.38", default-features = false, features = [ + "alloc", + "serde", +] } clap = { version = "4.5.4", features = ["derive"] } console = { version = "0.15.8" } -ocpi-tariffs = { version = "0.6.1", path = "../ocpi-tariffs", features = ["ocpi-v211"] } +ocpi-tariffs = { version = "0.6.1", path = "../ocpi-tariffs", features = [ + "ocpi-v211", +] } serde_json.workspace = true serde.workspace = true diff --git a/cli/src/cli.rs b/cli/src/cli.rs index f12c01f..48d32c1 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -11,12 +11,11 @@ use std::{ use chrono_tz::Tz; use clap::{Args, Parser, Subcommand, ValueEnum}; use console::style; -use serde::de::DeserializeOwned; - use ocpi_tariffs::{ ocpi::{cdr::Cdr, tariff::OcpiTariff, v211}, pricer::{Pricer, Report}, }; +use serde::de::DeserializeOwned; use crate::{error::Error, Result}; @@ -180,7 +179,7 @@ pub struct Validate { } impl Validate { - #[allow(clippy::too_many_lines)] + #[expect(clippy::too_many_lines)] fn run(self) -> Result<()> { let (report, cdr, _) = self.args.load_all()?; diff --git a/clippy.toml b/clippy.toml index 4ad92f3..f57df9b 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1,8 +1,8 @@ disallowed-methods = [ - { path = "std::option::Option::map_or", reason = "prefer `map(..).unwrap_or(..)` for legibility" }, - { path = "std::option::Option::map_or_else", reason = "prefer `map(..).unwrap_or_else(..)` for legibility" }, - { path = "std::result::Result::map_or", reason = "prefer `map(..).unwrap_or(..)` for legibility" }, - { path = "std::result::Result::map_or_else", reason = "prefer `map(..).unwrap_or_else(..)` for legibility" }, - { path = "std::iter::Iterator::for_each", reason = "prefer `for` for side-effects" }, - { path = "std::iter::Iterator::try_for_each", reason = "prefer `for` for side-effects" }, + { path = "std::option::Option::map_or", reason = "prefer `map(..).unwrap_or(..)` for legibility" }, + { path = "std::option::Option::map_or_else", reason = "prefer `map(..).unwrap_or_else(..)` for legibility" }, + { path = "std::result::Result::map_or", reason = "prefer `map(..).unwrap_or(..)` for legibility" }, + { path = "std::result::Result::map_or_else", reason = "prefer `map(..).unwrap_or_else(..)` for legibility" }, + { path = "std::iter::Iterator::for_each", reason = "prefer `for` for side-effects" }, + { path = "std::iter::Iterator::try_for_each", reason = "prefer `for` for side-effects" }, ] diff --git a/deny.toml b/deny.toml index 951f72b..efba481 100644 --- a/deny.toml +++ b/deny.toml @@ -26,7 +26,7 @@ allow = ["Apache-2.0", "MIT"] # ignore the local workspace crates [licenses.private] -ignore = true +ignore = true [[licenses.exceptions]] allow = ["Unicode-DFS-2016"] diff --git a/ocpi-tariffs/Cargo.toml b/ocpi-tariffs/Cargo.toml index 9d97363..43f8d12 100644 --- a/ocpi-tariffs/Cargo.toml +++ b/ocpi-tariffs/Cargo.toml @@ -17,7 +17,9 @@ workspace = true chrono-tz.workspace = true chrono = { version = "0.4.35", default-features = false, features = ["serde"] } rust_decimal_macros = "1.34.2" -rust_decimal = { version = "1.32.0", features = ["serde-with-arbitrary-precision"] } +rust_decimal = { version = "1.32.0", features = [ + "serde-with-arbitrary-precision", +] } serde.workspace = true [dev-dependencies] diff --git a/ocpi-tariffs/src/ocpi/v211/cdr.rs b/ocpi-tariffs/src/ocpi/v211/cdr.rs index 1bba451..b371255 100644 --- a/ocpi-tariffs/src/ocpi/v211/cdr.rs +++ b/ocpi-tariffs/src/ocpi/v211/cdr.rs @@ -1,14 +1,14 @@ use serde::{Deserialize, Serialize}; use super::tariff::OcpiTariff; - -use crate::{null_default, ocpi::v221}; - -use crate::types::money::Money; -use crate::types::{ - electricity::{Ampere, Kwh}, - money::Price, - time::{DateTime, HoursDecimal}, +use crate::{ + null_default, + ocpi::v221, + types::{ + electricity::{Ampere, Kwh}, + money::{Money, Price}, + time::{DateTime, HoursDecimal}, + }, }; /// The CDR object describes the Charging Session and its costs. How these costs are build up etc. diff --git a/ocpi-tariffs/src/ocpi/v211/tariff.rs b/ocpi-tariffs/src/ocpi/v211/tariff.rs index 0928826..cdb48a6 100644 --- a/ocpi-tariffs/src/ocpi/v211/tariff.rs +++ b/ocpi-tariffs/src/ocpi/v211/tariff.rs @@ -1,18 +1,18 @@ //! The Tariff object describes a tariff and its properties -use crate::null_default; - use serde::{Deserialize, Serialize}; use v221::tariff::CompatibilityVat; -use crate::types::{ - electricity::{Kw, Kwh}, - money::Money, - time::{DateTime, DayOfWeek, OcpiDate, OcpiTime, SecondsRound}, +use crate::{ + null_default, + ocpi::v221, + types::{ + electricity::{Kw, Kwh}, + money::Money, + time::{DateTime, DayOfWeek, OcpiDate, OcpiTime, SecondsRound}, + }, }; -use crate::ocpi::v221; - /// The Tariff object describes a tariff and its properties #[derive(Clone, Deserialize, Serialize)] pub struct OcpiTariff { diff --git a/ocpi-tariffs/src/ocpi/v221/cdr.rs b/ocpi-tariffs/src/ocpi/v221/cdr.rs index 8037139..a7369c0 100644 --- a/ocpi-tariffs/src/ocpi/v221/cdr.rs +++ b/ocpi-tariffs/src/ocpi/v221/cdr.rs @@ -1,13 +1,13 @@ use serde::{Deserialize, Serialize}; use super::tariff::OcpiTariff; - -use crate::null_default; - -use crate::types::{ - electricity::{Ampere, Kw, Kwh}, - money::Price, - time::{DateTime, HoursDecimal}, +use crate::{ + null_default, + types::{ + electricity::{Ampere, Kw, Kwh}, + money::Price, + time::{DateTime, HoursDecimal}, + }, }; /// The CDR object describes the Charging Session and its costs. How these costs are build up etc. diff --git a/ocpi-tariffs/src/ocpi/v221/tariff.rs b/ocpi-tariffs/src/ocpi/v221/tariff.rs index ad099d7..4ab73a8 100644 --- a/ocpi-tariffs/src/ocpi/v221/tariff.rs +++ b/ocpi-tariffs/src/ocpi/v221/tariff.rs @@ -2,14 +2,15 @@ use serde::{Deserialize, Serialize}; -use crate::types::{ - electricity::{Ampere, Kw, Kwh}, - money::{Money, Price, Vat}, - time::{DateTime, DayOfWeek, OcpiDate, OcpiTime, SecondsRound}, +use crate::{ + null_default, + types::{ + electricity::{Ampere, Kw, Kwh}, + money::{Money, Price, Vat}, + time::{DateTime, DayOfWeek, OcpiDate, OcpiTime, SecondsRound}, + }, }; -use crate::null_default; - /// The Tariff object describes a tariff and its properties #[derive(Clone, Deserialize, Serialize)] pub struct OcpiTariff { diff --git a/ocpi-tariffs/src/pricer.rs b/ocpi-tariffs/src/pricer.rs index a00baaf..a4f47d1 100644 --- a/ocpi-tariffs/src/pricer.rs +++ b/ocpi-tariffs/src/pricer.rs @@ -1,3 +1,7 @@ +use chrono::{DateTime, Utc}; +use chrono_tz::Tz; +use serde::Serialize; + use crate::{ ocpi::{ cdr::Cdr, @@ -14,10 +18,6 @@ use crate::{ Error, Result, }; -use chrono::{DateTime, Utc}; -use chrono_tz::Tz; -use serde::Serialize; - /// Pricer that encapsulates a single charge-session and a list of tariffs. /// To run the pricer call `build_report`. The resulting report contains the totals, subtotals and a breakdown of the /// calculation. @@ -87,7 +87,7 @@ impl<'a> Pricer<'a> { /// Attempt to apply the first applicable tariff to the charge session and build a report /// containing the results. - #[allow(clippy::too_many_lines)] + #[expect(clippy::too_many_lines)] pub fn build_report(self) -> Result { let cdr_tz = self.cdr.cdr_location.time_zone.as_ref(); diff --git a/ocpi-tariffs/src/restriction.rs b/ocpi-tariffs/src/restriction.rs index 528c25e..928588d 100644 --- a/ocpi-tariffs/src/restriction.rs +++ b/ocpi-tariffs/src/restriction.rs @@ -2,9 +2,11 @@ use std::collections::HashSet; use chrono::{Duration, NaiveDate, NaiveTime, Timelike, Weekday}; -use crate::ocpi::tariff::OcpiTariffRestriction; -use crate::session::{InstantData, PeriodData}; -use crate::types::electricity::{Ampere, Kw, Kwh}; +use crate::{ + ocpi::tariff::OcpiTariffRestriction, + session::{InstantData, PeriodData}, + types::electricity::{Ampere, Kw, Kwh}, +}; pub fn collect_restrictions(restriction: &OcpiTariffRestriction) -> Vec { let mut collected = Vec::new(); @@ -100,7 +102,7 @@ pub enum Restriction { MinDuration(Duration), MaxDuration(Duration), DayOfWeek(HashSet), - #[allow(dead_code)] + #[expect(dead_code)] Reservation, } diff --git a/ocpi-tariffs/src/session.rs b/ocpi-tariffs/src/session.rs index d918944..c374aeb 100644 --- a/ocpi-tariffs/src/session.rs +++ b/ocpi-tariffs/src/session.rs @@ -1,3 +1,6 @@ +use chrono::{Datelike, Duration, NaiveDate, NaiveTime, Weekday}; +use chrono_tz::Tz; + use crate::{ ocpi::cdr::{Cdr, OcpiCdrDimension, OcpiChargingPeriod}, types::{ @@ -6,9 +9,6 @@ use crate::{ }, }; -use chrono::{Datelike, Duration, NaiveDate, NaiveTime, Weekday}; -use chrono_tz::Tz; - pub struct ChargeSession { pub start_date_time: DateTime, pub periods: Vec, diff --git a/ocpi-tariffs/src/tariff.rs b/ocpi-tariffs/src/tariff.rs index fe69aca..c9b93be 100644 --- a/ocpi-tariffs/src/tariff.rs +++ b/ocpi-tariffs/src/tariff.rs @@ -1,13 +1,14 @@ use serde::Serialize; -use crate::ocpi::tariff::{ - CompatibilityVat, OcpiPriceComponent, OcpiTariff, OcpiTariffElement, TariffDimensionType, +use crate::{ + ocpi::tariff::{ + CompatibilityVat, OcpiPriceComponent, OcpiTariff, OcpiTariffElement, TariffDimensionType, + }, + restriction::{collect_restrictions, Restriction}, + session::ChargePeriod, + types::{money::Money, time::DateTime}, }; -use crate::restriction::{collect_restrictions, Restriction}; -use crate::session::ChargePeriod; -use crate::types::{money::Money, time::DateTime}; - pub struct Tariff { pub id: String, elements: Vec, @@ -124,7 +125,7 @@ impl TariffElement { } // use this in the future to validate if a period is still valid when it ends. - #[allow(dead_code)] + #[expect(dead_code)] pub fn is_active_at_end(&self, period: &ChargePeriod) -> bool { for restriction in &self.restrictions { if !restriction.instant_validity_inclusive(&period.end_instant) { diff --git a/ocpi-tariffs/src/types/money.rs b/ocpi-tariffs/src/types/money.rs index d862857..baf4aba 100644 --- a/ocpi-tariffs/src/types/money.rs +++ b/ocpi-tariffs/src/types/money.rs @@ -1,6 +1,7 @@ -use serde::{Deserialize, Serialize}; use std::fmt::Display; +use serde::{Deserialize, Serialize}; + use super::{electricity::Kwh, number::Number, time::HoursDecimal}; /// A price consisting of a value including VAT, and a value excluding VAT. diff --git a/ocpi-tariffs/src/types/time.rs b/ocpi-tariffs/src/types/time.rs index d2ce1f9..3fada1a 100644 --- a/ocpi-tariffs/src/types/time.rs +++ b/ocpi-tariffs/src/types/time.rs @@ -4,9 +4,8 @@ use chrono::Duration; use chrono_tz::Tz; use serde::{Deserialize, Serialize, Serializer}; -use crate::Error; - use super::number::Number; +use crate::Error; const SECS_IN_MIN: i64 = 60; const MINS_IN_HOUR: i64 = 60; @@ -304,9 +303,8 @@ mod hour_decimal_tests { use chrono::Duration; use rust_decimal_macros::dec; - use crate::types::number::Number; - use super::HoursDecimal; + use crate::types::number::Number; #[test] fn zero_minutes_should_be_zero_hours() { diff --git a/ocpi-tariffs/tests/integration.rs b/ocpi-tariffs/tests/integration.rs index d6c1fb3..3fb82ca 100644 --- a/ocpi-tariffs/tests/integration.rs +++ b/ocpi-tariffs/tests/integration.rs @@ -1,11 +1,11 @@ +use std::path::Path; + use chrono_tz::Tz; use ocpi_tariffs::{ ocpi::{cdr::Cdr, tariff::OcpiTariff}, pricer::Pricer, }; -use std::path::Path; -#[allow(clippy::needless_pass_by_value)] #[test_each::file(glob = "ocpi-tariffs/test_data/*/cdr*.json", name(segments = 2))] fn test_json(cdr: &str, path: &Path) { let tariff = std::fs::read_to_string(path.parent().unwrap().join("tariff.json")).unwrap();