pub struct Field<'a> {
pub name: &'a str,
pub value: Option<&'a InputValue>,
pub input: &'a IndexMap<String, InputValue>,
/* private fields */
}Expand description
A submitted field passed to a validation rule.
A field inside a list uses its submitted keys in its path, such as users.2.name. input holds
the whole input, so a rule can compare the field with other fields.
Fields§
§name: &'a strThe field’s dotted path, such as address.city.
value: Option<&'a InputValue>The submitted value, or None when the input doesn’t have the field.
input: &'a IndexMap<String, InputValue>The complete input, including fields outside the current list or map entry.
Implementations§
Source§impl<'a> Field<'a>
impl<'a> Field<'a>
Sourcepub fn label(&self) -> String
pub fn label(&self) -> String
Returns the field’s label. A field without a label returns its path in words, so
lastName and last_name both return last name. A path with a list index keeps its
spelling, such as members.0.firstName.
Sourcepub fn other_label(&self, name: &str) -> String
pub fn other_label(&self, name: &str) -> String
Returns another field’s label. name resolves relative to the object that declares this
rule, and a serde alias returns the label of the field it belongs to. Like
label, a field without a label returns its full path in words.
Sourcepub fn reject(&self, message: impl Into<Message>) -> RuleError
pub fn reject(&self, message: impl Into<Message>) -> RuleError
Returns an error that rejects this field with a message template.
The message fills in :attribute, :index, and :position. To fill in other
placeholders, pass a Message. Unknown placeholders stay as written. When the field sets
a message override for a named custom rule, the override replaces this template.
use laravel::validation::{Field, RuleError, ValidationRule};
struct Slug;
impl ValidationRule for Slug {
async fn validate(&self, field: &Field<'_>) -> Result<(), RuleError> {
Err(field.reject("The :attribute field must be a slug."))
}
}Sourcepub fn get(&self, name: &str) -> Option<&'a InputValue>
pub fn get(&self, name: &str) -> Option<&'a InputValue>
Returns another field’s submitted value, or None when it’s missing.
name resolves relative to the object that declares this rule, so inside a list or map
entry it stays within that entry without splitting ancestor keys on .. Use dots to reach
nested fields. A declared field also looks up its serde aliases, and the value under the
primary name takes precedence.
Trait Implementations§
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for Field<'a>
impl<'a> !UnwindSafe for Field<'a>
impl<'a> Forget for Field<'a>
impl<'a> Freeze for Field<'a>
impl<'a> Move for Field<'a>
impl<'a> Send for Field<'a>
impl<'a> Sync for Field<'a>where
RawVecInner: Sync,
Arc<Stored>: Sync,
RawTable<usize>: Sync,
Arc<dyn ErasedRule>: Sync,
BoxRaw<Kind>: Sync,
Arc<RegexI>: Sync,
BoxRaw<Pool<Cache, Box<dyn Fn() -> Cache + Sync + Send + UnwindSafe + RefUnwindSafe>>>: Sync,
Arc<str>: Sync,
Arc<dyn DatabaseRule>: Sync,
BoxRaw<[u8]>: Sync,
BoxRaw<ByteStr>: Sync,
Bytes: Sync,
BoxRaw<[Pos]>: Sync,
BoxRaw<HashMap<TypeId, Box<dyn AnyClone + Sync + Send>, BuildHasherDefault<IdHasher>>>: Sync,
SyncWrapper<Body>: Sync,
Arc<IndexMap<String, InputValue>>: Sync,
Mutex<Vec<Vec<String>>>: Sync,
impl<'a> Unpin for Field<'a>
impl<'a> UnsafeUnpin for Field<'a>where
&'a str: UnsafeUnpin,
&'a InputValue: UnsafeUnpin,
&'a IndexMap<String, InputValue>: UnsafeUnpin,
&'a Rules: UnsafeUnpin,
&'a Presentation: UnsafeUnpin,
&'a Request: UnsafeUnpin,
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
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> 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> ⓘ
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 more