Skip to content

Commit 0d60b69

Browse files
feat: use constant-string crate (#97)
1 parent a73790c commit 0d60b69

13 files changed

Lines changed: 35 additions & 141 deletions

File tree

Cargo.lock

Lines changed: 15 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ version = "0.2.11"
1111

1212
[workspace.dependencies]
1313
chrono = "0.4.42"
14+
constant-string = "0.0.2"
1415
email_address = { version = "0.2.9", default-features = false }
1516
fortifier = { path = "./packages/fortifier", version = "0.2.0" }
1617
fortifier-macros = { path = "./packages/fortifier-macros", version = "0.2.0" }

packages/fortifier-macros-tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ignored = ["chrono", "rust_decimal", "uuid"]
2020

2121
[dev-dependencies]
2222
chrono.workspace = true
23+
constant-string.workspace = true
2324
email_address.workspace = true
2425
fortifier = { workspace = true, features = [
2526
"all-types",

packages/fortifier-macros-tests/tests/validations/custom/options_pass.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use fortifier::{Validate, error_code};
1+
use constant_string::constant_string;
2+
use fortifier::Validate;
23
use serde::{Deserialize, Serialize};
34

45
#[derive(Deserialize, Serialize, Validate)]
@@ -35,7 +36,7 @@ struct CustomData<'a> {
3536
strip_to_two_options_from_three: Option<Option<Option<&'a str>>>,
3637
}
3738

38-
error_code!(CustomErrorCode, CUSTOM_ERROR_CODE, "custom");
39+
constant_string!(CustomErrorCode, CUSTOM_ERROR_CODE, "custom");
3940

4041
#[derive(Debug, Deserialize, PartialEq, Serialize)]
4142
#[serde(rename_all = "camelCase")]

packages/fortifier/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,18 @@ regex = ["dep:regex"]
2626
serde = [
2727
"dep:serde",
2828
"chrono?/serde",
29+
"constant-string/serde",
2930
"email_address?/serde_support",
3031
"fortifier-macros?/serde",
3132
"uuid?/serde",
3233
]
3334
url = ["dep:url"]
34-
utoipa = ["dep:utoipa", "fortifier-macros?/utoipa"]
35+
utoipa = ["dep:utoipa", "constant-string/utoipa", "fortifier-macros?/utoipa"]
3536
uuid = ["dep:uuid"]
3637

3738
[dependencies]
3839
chrono = { workspace = true, optional = true }
40+
constant-string.workspace = true
3941
email_address = { workspace = true, default-features = false, optional = true }
4042
fortifier-macros = { workspace = true, optional = true }
4143
indexmap = { workspace = true, optional = true }

packages/fortifier/src/error_code.rs

Lines changed: 0 additions & 117 deletions
This file was deleted.

packages/fortifier/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! Fortifier.
44
55
mod error;
6-
mod error_code;
76
mod integrations;
87
mod validate;
98
mod validations;

packages/fortifier/src/validations/email_address.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ use std::{
77
sync::Arc,
88
};
99

10+
use constant_string::constant_string;
1011
use email_address::EmailAddress;
1112
pub use email_address::Options as EmailAddressOptions;
1213

13-
use crate::error_code;
14-
15-
error_code!(
14+
constant_string!(
1615
EmailAddressErrorCode,
1716
EMAIL_ADDRESS_ERROR_CODE,
1817
"emailAddress"

packages/fortifier/src/validations/length.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ use std::{
88
sync::Arc,
99
};
1010

11+
use constant_string::constant_string;
1112
#[cfg(feature = "indexmap")]
1213
use indexmap::{IndexMap, IndexSet};
1314

14-
use crate::error_code;
15-
16-
error_code!(LengthErrorCode, LENGTH_ERROR_CODE, "length");
15+
constant_string!(LengthErrorCode, LENGTH_ERROR_CODE, "length");
1716

1817
/// Length validation error.
1918
#[derive(Debug, Eq, PartialEq)]

packages/fortifier/src/validations/phone_number.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ use std::{
77
sync::Arc,
88
};
99

10+
use constant_string::constant_string;
1011
pub use phonenumber::country::Id as PhoneNumberCountry;
1112
use phonenumber::{ParseError, PhoneNumber};
1213

13-
use crate::error_code;
14-
15-
error_code!(PhoneNumberErrorCode, PHONE_NUMBER_ERROR_CODE, "phoneNumber");
14+
constant_string!(PhoneNumberErrorCode, PHONE_NUMBER_ERROR_CODE, "phoneNumber");
1615

1716
/// Phone number validation error.
1817
#[derive(Debug, Eq, PartialEq)]

0 commit comments

Comments
 (0)