From 7bf6de67e8b1b5ac10d3efec097e51ec126f3e3b Mon Sep 17 00:00:00 2001 From: zeon256 Date: Mon, 29 Jan 2024 01:54:19 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=9A=20chore:=20default=20impl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 2 +- src/bus_enums.rs | 28 ++++++++-------------------- src/lib.rs | 3 ++- src/utils.rs | 4 +++- 4 files changed, 14 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 03cd337..47870c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "lta_models" version = "0.6.0" -authors = ["budinverse "] +authors = ["zeon256 "] edition = "2021" license = "MIT" description = "🚍Models for lta-rs" diff --git a/src/bus_enums.rs b/src/bus_enums.rs index 8f45a23..e9c6993 100644 --- a/src/bus_enums.rs +++ b/src/bus_enums.rs @@ -37,7 +37,7 @@ pub enum Operator { /// DD -> Double Decker /// /// BD -> Bendy -#[derive(Debug, Clone, PartialEq, PartialOrd, Deserialize, Serialize)] +#[derive(Debug, Clone, PartialEq, PartialOrd, Deserialize, Serialize, Default)] #[serde(rename_all = "PascalCase")] pub enum BusType { #[serde(rename = "SD")] @@ -49,22 +49,17 @@ pub enum BusType { #[serde(rename = "BD")] Bendy, + #[default] #[serde(other)] Unknown, } -impl Default for BusType { - fn default() -> Self { - BusType::Unknown - } -} - /// SEA -> Seats available /// /// SDA -> Standing available /// /// LSD -> Limited standing -#[derive(Debug, Clone, PartialEq, PartialOrd, Deserialize, Serialize)] +#[derive(Debug, Clone, PartialEq, PartialOrd, Deserialize, Serialize, Default)] pub enum BusLoad { #[serde(rename = "SEA")] SeatsAvailable, @@ -75,32 +70,24 @@ pub enum BusLoad { #[serde(rename = "LSD")] LimitedStanding, + #[default] #[serde(other)] Unknown, } -impl Default for BusLoad { - fn default() -> Self { - BusLoad::Unknown - } -} -#[derive(Debug, Clone, PartialEq, PartialOrd, Deserialize, Serialize)] +#[derive(Debug, Clone, PartialEq, PartialOrd, Deserialize, Serialize, Default)] pub enum BusFeature { #[serde(rename = "WAB")] WheelChairAccessible, + #[default] #[serde(other)] Unknown, } -impl Default for BusFeature { - fn default() -> Self { - BusFeature::Unknown - } -} -#[derive(Debug, Clone, PartialEq, PartialOrd, Deserialize, Serialize)] +#[derive(Debug, Clone, PartialEq, PartialOrd, Deserialize, Serialize, Default)] pub enum BusCategory { #[serde(alias = "EXPRESS")] Express, @@ -132,6 +119,7 @@ pub enum BusCategory { #[serde(alias = "FLAT FARE $2.00")] FlatFareTwoDollar, + #[default] #[serde(other)] Unknown, } diff --git a/src/lib.rs b/src/lib.rs index e392507..1cba131 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,11 @@ //! Data Structures for lta-rs and for LTA datamall APIs // Forbid warnings in release builds: +#![forbid(unsafe_code)] #![cfg_attr(not(debug_assertions), deny(warnings))] #![warn( clippy::all, + clippy::linkedlist, clippy::await_holding_lock, clippy::char_lit_as_u8, clippy::checked_conversions, @@ -26,7 +28,6 @@ clippy::invalid_upcast_comparisons, clippy::large_types_passed_by_value, clippy::let_unit_value, - clippy::linkedlist, clippy::lossy_float_literal, clippy::macro_use_imports, clippy::manual_ok_or, diff --git a/src/utils.rs b/src/utils.rs index afbecfe..8db9922 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -234,7 +234,9 @@ pub mod de { write!(f, "StringWrapErr") } } - + + /// # Errors + /// Fails when data cant be deserialized to String pub fn treat_error_as_none<'de, T, D>(deserializer: D) -> Result, D::Error> where T: Deserialize<'de>,