pub enum RuleError {
Invalid(String),
Failed(Error),
}Expand description
The error a custom rule returns: a rejected field, or a check that couldn’t run.
To reject invalid input, return RuleError::invalid or Field::reject.
Propagate service and I/O errors with ?, including laravel::Result failures
from the database or cache. Those errors stop validation and reach the application’s error
handler with their original status, headers, and location.
use laravel::validation::{Field, RuleError, ValidationRule};
struct NotReserved;
impl ValidationRule for NotReserved {
async fn validate(&self, field: &Field<'_>) -> Result<(), RuleError> {
match field.value.and_then(|value| value.as_str()) {
Some("admin" | "root") => Err(RuleError::invalid("This username is reserved.")),
_ => Ok(()),
}
}
}Variants§
Invalid(String)
The field is invalid. The string is the message to show for the field.
Failed(Error)
The check couldn’t run, such as when the database is unavailable.
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl Forget for RuleError
impl Freeze for RuleErrorwhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
*const ArcInner<Inner> is !null: Freeze,
PhantomData<ArcInner<Inner>>: Freeze,
impl Move for RuleError
impl RefUnwindSafe for RuleErrorwhere
Atomic<usize>: RefUnwindSafe,
Error: RefUnwindSafe,
NonZero<u16>: RefUnwindSafe,
Atomic<*mut ()>: RefUnwindSafe,
impl Send for RuleError
impl Sync for RuleError
impl Unpin for RuleError
impl UnsafeUnpin for RuleErrorwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const ArcInner<Inner> is !null: UnsafeUnpin,
PhantomData<ArcInner<Inner>>: UnsafeUnpin,
impl UnwindSafe for RuleError
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<K> ForeignKey<K> for K
impl<K> ForeignKey<K> for K
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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> ⓘ
Converts
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> ⓘ
Converts
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 moreCreates a shared type from an unshared type.