Skip to content

Commit 530e115

Browse files
[Fix] (#25) Fix compile error when no regex feature is enabled
* fix: fix error when there's no regex support
1 parent 1d532a4 commit 530e115

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

src/valust-derive/src/config/struct_config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ impl StructOperation {
215215
message: fallible.message,
216216
fallible: true,
217217
}),
218+
#[cfg(feature = "regex")]
218219
ValidatorItem::Regex(regex) => Ok(Self {
219220
expr: func_only(regex.text)?,
220221
message: regex.message,

src/valust-derive/src/parse/parse_field_validator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ impl ValidatorItem {
8989
fallible: true,
9090
}
9191
}
92+
#[cfg(feature = "regex")]
9293
Self::Regex(RegexValidator { text, message, .. }) => FieldManualOperation {
9394
ty: FieldOperationType::Validate,
9495
expr: text,

src/valust-derive/src/utils/parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use syn::parse::{Parse, ParseStream};
2-
use syn::{Expr, Ident, LitStr, Token, parenthesized, parse_quote};
2+
use syn::{Expr, Ident, Token, parenthesized, parse_quote};
33

44
use super::regex_comp::CompatibleExpr;
55

66
pub enum Expression {
77
Expr(Expr),
88
Func(Expr),
99
#[cfg(feature = "regex")]
10-
Regex(LitStr),
10+
Regex(syn::LitStr),
1111
}
1212

1313
impl Parse for Expression {

src/valust-derive/src/utils/regex_comp.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
use proc_macro2::TokenStream;
2-
use quote::{ToTokens, format_ident, quote};
3-
use syn::{Expr, Ident, LitStr};
2+
use quote::ToTokens;
3+
#[cfg(feature = "regex")]
4+
use quote::{format_ident, quote};
5+
use syn::Expr;
46

57
pub enum CompatibleExpr {
68
Expr(Expr),
79
#[cfg(feature = "regex")]
810
#[allow(dead_code)]
9-
Regex(LitStr, Ident),
11+
Regex(syn::LitStr, syn::Ident),
1012
}
1113

1214
impl CompatibleExpr {
1315
pub fn as_expr(&self) -> TokenStream {
1416
match self {
1517
Self::Expr(e) => e.to_token_stream(),
18+
#[cfg(feature = "regex")]
1619
Self::Regex(text, input) => {
1720
let lock_init = quote! {
1821
::std::sync::LazyLock::new(|| {

0 commit comments

Comments
 (0)