Skip to content

Commit 1ef7048

Browse files
feat: use constant-string crate
1 parent a73790c commit 1ef7048

11 files changed

Lines changed: 32 additions & 141 deletions

File tree

Cargo.lock

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

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 = "0.0.2"
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)]

packages/fortifier/src/validations/range.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use std::{
66
sync::Arc,
77
};
88

9-
use crate::error_code;
9+
use constant_string::constant_string;
1010

11-
error_code!(RangeErrorCode, RANGE_ERROR_CODE, "range");
11+
constant_string!(RangeErrorCode, RANGE_ERROR_CODE, "range");
1212

1313
/// Range validation error.
1414
#[derive(Debug, Eq, PartialEq)]

packages/fortifier/src/validations/regex.rs

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

10+
use constant_string::constant_string;
1011
use regex::Regex;
1112

12-
use crate::error_code;
13-
1413
/// Convert to a regular expression.
1514
pub trait AsRegex {
1615
/// Convert to a regular expression.
@@ -38,7 +37,7 @@ where
3837
}
3938
}
4039

41-
error_code!(RegexErrorCode, REGEX_ERROR_CODE, "regex");
40+
constant_string!(RegexErrorCode, REGEX_ERROR_CODE, "regex");
4241

4342
/// Regular expression validation error.
4443
#[derive(Debug, Eq, PartialEq)]

0 commit comments

Comments
 (0)