Skip to content

Commit

Permalink
feat: derive some useful traits to internal types
Browse files Browse the repository at this point in the history
  • Loading branch information
ali77gh committed Feb 5, 2024
1 parent 091bdd3 commit 8a30187
Show file tree
Hide file tree
Showing 18 changed files with 31 additions and 31 deletions.
12 changes: 6 additions & 6 deletions src/bill/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use std::convert::From;
use std::str::FromStr;
use std::string::ToString;

#[derive(Debug, Clone, PartialEq, thiserror::Error)]
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, thiserror::Error)]
pub enum BillError {
#[error("Barcode length must be 26 chars")]
InvalidBarcodeLength,
Expand Down Expand Up @@ -95,7 +95,7 @@ pub enum BillError {
/// use rust_persian_tools::bill::BillType;
/// assert_eq!(FromPrimitive::from_u8(2), Some(BillType::Electricity));
/// ```
#[derive(FromPrimitive, Clone, Copy, PartialEq, Debug)]
#[derive(FromPrimitive, Clone, Copy, PartialEq, Eq, Debug, Hash)]
pub enum BillType {
/// آب
/// Service Type Code: 1
Expand Down Expand Up @@ -123,7 +123,7 @@ pub enum BillType {
DrivingOffence = 8,
}

#[derive(Debug, PartialEq)]
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
pub enum CurrencyType {
Rials,
Tomans,
Expand All @@ -136,7 +136,7 @@ pub enum CurrencyType {
///
/// Checksum is calculated via [ISSN Modulo 11 check digit](https://www.activebarcode.com/codes/checkdigit/modulo11)
///
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
pub struct BillID {
/// Maximum 8-digit Company Internal File ID
pub file_id: String,
Expand Down Expand Up @@ -216,7 +216,7 @@ impl ToString for BillID {
/// Checksums are calculated via [ISSN Modulo 11 check digit](https://www.activebarcode.com/codes/checkdigit/modulo11) \
/// Checksum1 is the checksum for Payment ID itself and only checks digits in Payment ID \
/// Checksum2 is the checksum for Bill ID and Payment ID concatenated together and checks validity of relation between two IDs
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
pub struct PaymentID {
/// Amount in scale 1000:1 (1000 will be 1)
amount: u64,
Expand Down Expand Up @@ -324,7 +324,7 @@ impl PaymentID {

/// Container for Both Bill and Payment IDs \
/// You must use this type to extract all informations about the bill
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
pub struct Bill {
pub bill_id: BillID,
pub payment_id: PaymentID,
Expand Down
2 changes: 1 addition & 1 deletion src/extract_card_number/extracted_card_number.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[derive(PartialEq, Eq, Debug)]
#[derive(PartialEq, Eq, Debug, Clone, Hash)]
pub struct ExtractedCardNumber {
base: String,
pure: String,
Expand Down
2 changes: 1 addition & 1 deletion src/get_bank_name_by_card_number/errors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use thiserror::Error;

#[derive(Error, Debug, PartialEq, Eq)]
#[derive(Error, Clone, PartialEq, Eq, Debug, Hash)]
pub enum BankNameByCardNumberError {
#[error("card number: {0:?} with length of {1:?} is too short minimum is 6")]
TooShort(String, usize),
Expand Down
2 changes: 1 addition & 1 deletion src/get_place_by_iran_national_id/errors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use thiserror::Error;

#[derive(Error, Debug, PartialEq, Eq)]
#[derive(Error, Debug, PartialEq, Eq, Clone, Copy, Hash)]
pub enum PlaceByNationalIdError {
#[error("national id is too short len:{0}")]
TooShortNationalId(usize),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[derive(PartialEq, Eq, Debug)]
#[derive(PartialEq, Eq, Debug, Clone, Copy, Hash)]
pub struct PlaceByNationalId {
city: &'static str,
province: &'static str,
Expand Down
2 changes: 1 addition & 1 deletion src/legal_id/errors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use thiserror::Error;

#[derive(Error, Debug, PartialEq, Eq)]
#[derive(Error, Debug, PartialEq, Eq, Clone, Copy, Hash)]
pub enum VerifyLegalIdError {
#[error("invalid len legal id should be 11 chars")]
InvalidLength,
Expand Down
2 changes: 1 addition & 1 deletion src/national_id/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use std::num::ParseIntError;
pub mod serde;

/// Possible errors during validation of Iranian National Number.
#[derive(Debug, PartialEq, thiserror::Error)]
#[derive(Debug, PartialEq, Eq, thiserror::Error)]
pub enum NationalIdError {
/// If input length is invalid.
#[error("Invalid length {0} for National Number")]
Expand Down
2 changes: 1 addition & 1 deletion src/number_plate/errors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use thiserror::Error;

#[derive(Error, Debug, PartialEq, Eq)]
#[derive(Error, Debug, PartialEq, Eq, Clone, Hash)]
pub enum PlateNumberError {
#[error("plate numbers must be 7 or 8 digits long")]
InvalidPlateDigitLength,
Expand Down
12 changes: 6 additions & 6 deletions src/number_plate/types.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
#[derive(PartialEq, Debug)]
#[derive(PartialEq, Debug, Clone, Copy, Hash, Eq)]
pub enum PlateTypes {
Car = 1,
Motorcycle = 2,
}

#[derive(PartialEq, Debug)]
#[derive(PartialEq, Debug, Clone, Hash, Eq)]
pub struct CarPlateDetail {
pub first_two_digits: String,
pub plate_character: String,
pub next_three_digits: String,
pub province_code: String,
}

#[derive(PartialEq, Debug)]
#[derive(PartialEq, Debug, Clone, Hash, Eq)]
pub struct MotorcyclePlateDetail {
pub digits: String,
pub province_code: String,
}

#[derive(PartialEq, Debug)]
#[derive(PartialEq, Debug, Clone, Hash, Eq)]
pub enum PlateResultDetails {
CarDetail(CarPlateDetail),
MotorcycleDetail(MotorcyclePlateDetail),
}

#[derive(PartialEq, Debug)]
#[derive(PartialEq, Debug, Clone, Hash, Eq)]
pub struct Plate {
pub template: String,
pub province: String,
Expand All @@ -33,7 +33,7 @@ pub struct Plate {
pub category: Option<String>,
}

#[derive(PartialEq, Debug)]
#[derive(PartialEq, Debug, Clone, Hash, Eq)]
pub struct NormalizedPlate {
pub numbers: String,
pub char: Option<String>,
Expand Down
2 changes: 1 addition & 1 deletion src/number_to_words/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use thiserror::Error;

#[derive(Error, Debug, PartialEq, Eq)]
#[derive(Error, Clone, Debug, Hash, PartialEq, Eq)]
pub enum NumberToWordsError {
#[error("number_to_words_str input is empty")]
EmptyString,
Expand Down
2 changes: 1 addition & 1 deletion src/phone_number/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use thiserror::Error;

pub static PREFIXES: [&str; 4] = ["+98", "98", "0098", "0"];

#[derive(Error, Debug)]
#[derive(Error, Clone, Debug, Hash, PartialEq, Eq)]
pub enum PhoneNumberError {
#[error("This prefix is not a valid phone number (prefix : `{0}`)")]
InvalidPrefix(String),
Expand Down
6 changes: 3 additions & 3 deletions src/phone_number/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ pub mod constants {
)];
}

#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, Hash, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Operator {
ShatelMobile,
Expand All @@ -403,14 +403,14 @@ pub enum Operator {
RightTel,
}

#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, Hash, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum SimType {
Permanent,
Credit,
}

#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Hash, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(bound(deserialize = "'de: 'a")))]
pub struct OperatorDetails<'a> {
Expand Down
2 changes: 1 addition & 1 deletion src/sheba/bank_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub(super) fn get_bank_info(s: u32) -> Option<ShebaResult> {
})
}

#[derive(PartialEq, Eq, Debug)]
#[derive(PartialEq, Eq, Debug, Clone, Copy, Hash)]
pub struct ShebaResult {
pub(super) name: &'static str,
pub(super) code: &'static str,
Expand Down
2 changes: 1 addition & 1 deletion src/sheba/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::num::ParseIntError;

use thiserror::Error;

#[derive(Error, Debug, PartialEq, Eq)]
#[derive(Error, Clone, Copy, Debug, Hash, PartialEq, Eq)]
pub enum ShebaValidationError {
#[error("empty")]
Empty,
Expand Down
4 changes: 2 additions & 2 deletions src/time_diff/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub(crate) const DAY: i64 = HOUR * 24;
pub(crate) const MONTH: i64 = DAY * 30;
pub(crate) const YEAR: i64 = DAY * 365;

#[derive(Error, Debug)]
#[derive(Error, Clone, Copy, Debug, Hash, PartialEq, Eq)]
pub enum TimeAgoError {
#[error("Wrong datetime format !")]
InvalidDateTimeFormat,
Expand All @@ -23,7 +23,7 @@ pub enum TimeAgoError {
/// the `long_form()` returns a long and exact desciption about time diffrence\
/// - 6 سال و 6 ماه و 10 روز و 12 دقیقه و 37 ثانیه بعد
///
#[derive(Debug, PartialEq)]
#[derive(PartialEq, Eq, Debug, Clone, Copy, Hash)]
pub struct TimeDiff {
pub years: u32,
pub months: u8,
Expand Down
1 change: 0 additions & 1 deletion src/url_fix/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::string::FromUtf8Error;
use urlencoding::decode;

pub enum UrlFixError {}

/// description Used for fix Persian characters in URL<br>
/// separator: space by default
Expand Down
2 changes: 1 addition & 1 deletion src/words_to_number/errors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use thiserror::Error;

#[derive(Error, Debug, PartialEq, Eq)]
#[derive(Error, Clone, Copy, Debug, Hash, PartialEq, Eq)]
pub enum WordsToNumberError {
#[error("There is a invalid unit in the input")]
InvalidUnit,
Expand Down
3 changes: 2 additions & 1 deletion src/words_to_number/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ use self::{
errors::WordsToNumberError,
};

#[derive(Debug, PartialEq)]
#[derive(PartialEq, Eq, Debug, Clone, Copy, Hash)]
pub enum Language {
Arabic,
Persian,
English,
}

#[derive(PartialEq, Eq, Debug, Clone, Copy, Hash)]
pub struct Options {
pub digits: Language,
pub add_commas: bool,
Expand Down

0 comments on commit 8a30187

Please sign in to comment.