Skip to content

Commit

Permalink
Add rust-version = 1.81 and fmt toml files and imports.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian committed Oct 7, 2024
1 parent 5749aeb commit 43cc126
Show file tree
Hide file tree
Showing 17 changed files with 79 additions and 70 deletions.
4 changes: 2 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -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",
]
9 changes: 7 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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()?;

Expand Down
12 changes: 6 additions & 6 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -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" },
]
2 changes: 1 addition & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
4 changes: 3 additions & 1 deletion ocpi-tariffs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
16 changes: 8 additions & 8 deletions ocpi-tariffs/src/ocpi/v211/cdr.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
16 changes: 8 additions & 8 deletions ocpi-tariffs/src/ocpi/v211/tariff.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions ocpi-tariffs/src/ocpi/v221/cdr.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
13 changes: 7 additions & 6 deletions ocpi-tariffs/src/ocpi/v221/tariff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions ocpi-tariffs/src/pricer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use chrono::{DateTime, Utc};
use chrono_tz::Tz;
use serde::Serialize;

use crate::{
ocpi::{
cdr::Cdr,
Expand All @@ -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.
Expand Down Expand Up @@ -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<Report> {
let cdr_tz = self.cdr.cdr_location.time_zone.as_ref();

Expand Down
10 changes: 6 additions & 4 deletions ocpi-tariffs/src/restriction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Restriction> {
let mut collected = Vec::new();
Expand Down Expand Up @@ -100,7 +102,7 @@ pub enum Restriction {
MinDuration(Duration),
MaxDuration(Duration),
DayOfWeek(HashSet<Weekday>),
#[allow(dead_code)]
#[expect(dead_code)]
Reservation,
}

Expand Down
6 changes: 3 additions & 3 deletions ocpi-tariffs/src/session.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use chrono::{Datelike, Duration, NaiveDate, NaiveTime, Weekday};
use chrono_tz::Tz;

use crate::{
ocpi::cdr::{Cdr, OcpiCdrDimension, OcpiChargingPeriod},
types::{
Expand All @@ -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<ChargePeriod>,
Expand Down
15 changes: 8 additions & 7 deletions ocpi-tariffs/src/tariff.rs
Original file line number Diff line number Diff line change
@@ -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<TariffElement>,
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion ocpi-tariffs/src/types/money.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 2 additions & 4 deletions ocpi-tariffs/src/types/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions ocpi-tariffs/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -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();
Expand Down

0 comments on commit 43cc126

Please sign in to comment.