pub struct ValidationPattern {
pub pattern: String,
pub description: String,
pub examples: Option<Vec<String>>,
}Expand description
Common validation patterns for field validation
§Examples
use reinhardt_rest::metadata::ValidationPattern;
let pattern = ValidationPattern::email();
assert!(pattern.is_valid("user@example.com"));
assert!(!pattern.is_valid("invalid-email"));Fields§
§pattern: StringThe regular expression pattern
description: StringDescription of what the pattern validates
examples: Option<Vec<String>>Example values that match this pattern
Implementations§
Source§impl ValidationPattern
impl ValidationPattern
Sourcepub fn new(
pattern: impl Into<String>,
description: impl Into<String>,
) -> ValidationPattern
Available on native and crate feature rest only.
pub fn new( pattern: impl Into<String>, description: impl Into<String>, ) -> ValidationPattern
native and crate feature rest only.Creates a new validation pattern
§Examples
use reinhardt_rest::metadata::ValidationPattern;
let pattern = ValidationPattern::new(
r"^\d{3}-\d{4}$",
"Phone number format (XXX-XXXX)"
);
assert_eq!(pattern.pattern, r"^\d{3}-\d{4}$");Sourcepub fn with_examples(
pattern: impl Into<String>,
description: impl Into<String>,
examples: Vec<impl Into<String>>,
) -> ValidationPattern
Available on native and crate feature rest only.
pub fn with_examples( pattern: impl Into<String>, description: impl Into<String>, examples: Vec<impl Into<String>>, ) -> ValidationPattern
native and crate feature rest only.Creates a new validation pattern with examples
§Examples
use reinhardt_rest::metadata::ValidationPattern;
let pattern = ValidationPattern::with_examples(
r"^\d{3}-\d{4}$",
"Phone number format",
vec!["123-4567", "555-0100"]
);
assert_eq!(pattern.examples.as_ref().unwrap().len(), 2);Sourcepub fn email() -> ValidationPattern
Available on native and crate feature rest only.
pub fn email() -> ValidationPattern
native and crate feature rest only.Email address pattern
§Examples
use reinhardt_rest::metadata::ValidationPattern;
let pattern = ValidationPattern::email();
assert!(pattern.is_valid("user@example.com"));
assert!(pattern.is_valid("test.user+tag@example.co.uk"));
assert!(!pattern.is_valid("invalid-email"));
assert!(!pattern.is_valid("@example.com"));Sourcepub fn url() -> ValidationPattern
Available on native and crate feature rest only.
pub fn url() -> ValidationPattern
native and crate feature rest only.URL pattern
§Examples
use reinhardt_rest::metadata::ValidationPattern;
let pattern = ValidationPattern::url();
assert!(pattern.is_valid("https://example.com"));
assert!(pattern.is_valid("http://example.com/path"));
assert!(!pattern.is_valid("not-a-url"));Sourcepub fn uuid() -> ValidationPattern
Available on native and crate feature rest only.
pub fn uuid() -> ValidationPattern
native and crate feature rest only.UUID pattern (version 4)
§Examples
use reinhardt_rest::metadata::ValidationPattern;
let pattern = ValidationPattern::uuid();
assert!(pattern.is_valid("123e4567-e89b-12d3-a456-426614174000"));
assert!(!pattern.is_valid("not-a-uuid"));Sourcepub fn alphanumeric() -> ValidationPattern
Available on native and crate feature rest only.
pub fn alphanumeric() -> ValidationPattern
native and crate feature rest only.Alphanumeric pattern (letters and numbers only)
§Examples
use reinhardt_rest::metadata::ValidationPattern;
let pattern = ValidationPattern::alphanumeric();
assert!(pattern.is_valid("abc123"));
assert!(pattern.is_valid("TestUser123"));
assert!(!pattern.is_valid("user@name"));
assert!(!pattern.is_valid("user-name"));Sourcepub fn slug() -> ValidationPattern
Available on native and crate feature rest only.
pub fn slug() -> ValidationPattern
native and crate feature rest only.Slug pattern (URL-friendly identifier)
§Examples
use reinhardt_rest::metadata::ValidationPattern;
let pattern = ValidationPattern::slug();
assert!(pattern.is_valid("my-blog-post"));
assert!(pattern.is_valid("article-123"));
assert!(!pattern.is_valid("My Blog Post"));
assert!(!pattern.is_valid("article_123"));Sourcepub fn phone() -> ValidationPattern
Available on native and crate feature rest only.
pub fn phone() -> ValidationPattern
native and crate feature rest only.Phone number pattern (international format)
§Examples
use reinhardt_rest::metadata::ValidationPattern;
let pattern = ValidationPattern::phone();
assert!(pattern.is_valid("+1-234-567-8900"));
assert!(pattern.is_valid("+81-90-1234-5678"));
assert!(!pattern.is_valid("123-456-7890")); // Missing country codeSourcepub fn hex_color() -> ValidationPattern
Available on native and crate feature rest only.
pub fn hex_color() -> ValidationPattern
native and crate feature rest only.Hex color pattern
§Examples
use reinhardt_rest::metadata::ValidationPattern;
let pattern = ValidationPattern::hex_color();
assert!(pattern.is_valid("#FF5733"));
assert!(pattern.is_valid("#fff"));
assert!(!pattern.is_valid("FF5733")); // Missing #
assert!(!pattern.is_valid("#GG5733")); // Invalid hexSourcepub fn ipv4() -> ValidationPattern
Available on native and crate feature rest only.
pub fn ipv4() -> ValidationPattern
native and crate feature rest only.IP address pattern (IPv4)
§Examples
use reinhardt_rest::metadata::ValidationPattern;
let pattern = ValidationPattern::ipv4();
assert!(pattern.is_valid("192.168.1.1"));
assert!(pattern.is_valid("10.0.0.1"));
assert!(!pattern.is_valid("256.1.1.1")); // Invalid range
assert!(!pattern.is_valid("192.168.1")); // IncompleteSourcepub fn date() -> ValidationPattern
Available on native and crate feature rest only.
pub fn date() -> ValidationPattern
native and crate feature rest only.Date pattern (YYYY-MM-DD)
Note: This pattern only validates the format, not the validity of the date itself. For example, it will accept “2023-13-01” (invalid month) or “2023-02-30” (invalid day). Use a proper date parsing library for full validation.
§Examples
use reinhardt_rest::metadata::ValidationPattern;
let pattern = ValidationPattern::date();
assert!(pattern.is_valid("2023-12-25"));
assert!(pattern.is_valid("2024-01-01"));
assert!(!pattern.is_valid("23-12-25")); // Wrong format
assert!(!pattern.is_valid("2023/12/25")); // Wrong separatorSourcepub fn time() -> ValidationPattern
Available on native and crate feature rest only.
pub fn time() -> ValidationPattern
native and crate feature rest only.Time pattern (HH:MM:SS)
§Examples
use reinhardt_rest::metadata::ValidationPattern;
let pattern = ValidationPattern::time();
assert!(pattern.is_valid("14:30:00"));
assert!(pattern.is_valid("09:05:30"));
assert!(!pattern.is_valid("25:00:00")); // Invalid hour
assert!(!pattern.is_valid("14:30")); // Missing secondsSourcepub fn is_valid(&self, value: &str) -> bool
Available on native and crate feature rest only.
pub fn is_valid(&self, value: &str) -> bool
native and crate feature rest only.Validates if a value matches this pattern
§Examples
use reinhardt_rest::metadata::ValidationPattern;
let pattern = ValidationPattern::email();
assert!(pattern.is_valid("user@example.com"));
assert!(!pattern.is_valid("invalid"));Sourcepub fn as_openapi_pattern(&self) -> &str
Available on native and crate feature rest only.
pub fn as_openapi_pattern(&self) -> &str
native and crate feature rest only.Returns the pattern as a string for use in OpenAPI schemas
§Examples
use reinhardt_rest::metadata::ValidationPattern;
let pattern = ValidationPattern::email();
assert!(pattern.as_openapi_pattern().starts_with('^'));Trait Implementations§
Source§impl Clone for ValidationPattern
impl Clone for ValidationPattern
Source§fn clone(&self) -> ValidationPattern
fn clone(&self) -> ValidationPattern
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ValidationPattern
impl Debug for ValidationPattern
Source§impl<'de> Deserialize<'de> for ValidationPattern
impl<'de> Deserialize<'de> for ValidationPattern
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ValidationPattern, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ValidationPattern, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for ValidationPattern
impl Serialize for ValidationPattern
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for ValidationPattern
impl RefUnwindSafe for ValidationPattern
impl Send for ValidationPattern
impl Sync for ValidationPattern
impl Unpin for ValidationPattern
impl UnsafeUnpin for ValidationPattern
impl UnwindSafe for ValidationPattern
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
type Err = Infallible
fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<E> ServerFnErrorAssertions<E> for Ewhere
E: Debug,
impl<E> ServerFnErrorAssertions<E> for Ewhere
E: Debug,
Source§fn should_contain_message(&self, expected: &str)where
E: Display,
fn should_contain_message(&self, expected: &str)where
E: Display,
Source§fn should_have_message(&self, expected: &str)where
E: Display,
fn should_have_message(&self, expected: &str)where
E: Display,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.