pub struct LazyRegex<T = LazyLock<Regex>>(pub T);Expand description
Transparent wrapper around a type dereferencing to a Regex. Can be used as a separator,
or in param validation.
§Why a separate type?
A separate type is necessary to circumvent orphaning rules. We want to implement Split
and Validate for any type (e.g., LazyLock) that lazily initializes a Regex,
since a Regex on its own cannot be initialized in compile time. Similarly, such a type cannot
be dereferenced in compile time, which rules out implementing these traits for &'static Regex.
§Examples
The easiest way to initialize a wrapper is the lazy_regex! macro.
use smart_config::{de::Delimited, pat::{lazy_regex, LazyRegex}};
static NAME_REGEX: LazyRegex = lazy_regex!(r"^[a-z][-a-z0-9]*$");
#[derive(DescribeConfig, DeserializeConfig)]
struct TestConfig {
#[config(validate(NAME_REGEX))]
app: String,
// The macro also can be inlined!
#[config(with = Delimited::new(lazy_regex!(ref r"\s*,\s*")))]
numbers: Vec<u64>,
}Tuple Fields§
§0: TTrait Implementations§
Source§impl<T> Split for &'static LazyRegex<T>
impl<T> Split for &'static LazyRegex<T>
Source§fn split_once<'s>(&self, haystack: &'s str) -> Option<(&'s str, &'s str)>
fn split_once<'s>(&self, haystack: &'s str) -> Option<(&'s str, &'s str)>
Splits the given
haystack at most once from its start. This generalizes str::split_once().Auto Trait Implementations§
impl<T> Freeze for LazyRegex<T>where
T: Freeze,
impl<T> RefUnwindSafe for LazyRegex<T>where
T: RefUnwindSafe,
impl<T> Send for LazyRegex<T>where
T: Send,
impl<T> Sync for LazyRegex<T>where
T: Sync,
impl<T> Unpin for LazyRegex<T>where
T: Unpin,
impl<T> UnwindSafe for LazyRegex<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more