pub struct Field<'v> { /* private fields */ }Expand description
The rules for one field, chained: v.field("name", &self.name).required().max(100).
Implementations§
Source§impl Field<'_>
impl Field<'_>
Sourcepub fn message(self, message: impl Into<String>) -> Self
pub fn message(self, message: impl Into<String>) -> Self
Replaces this field’s error so far with message: the error of the
rule just before it, or of any earlier rule that failed (only one error
is kept per field). A database or async check just before it gets the
message when it fails.
Sourcepub fn required(self) -> Self
pub fn required(self) -> Self
Fails when the value is missing: None, or text that is blank after trimming.
Sourcepub fn min(self, min: impl Into<f64>) -> Self
pub fn min(self, min: impl Into<f64>) -> Self
At least min characters, items, kilobytes (files), or as a number.
Sourcepub fn max(self, max: impl Into<f64>) -> Self
pub fn max(self, max: impl Into<f64>) -> Self
At most max characters, items, kilobytes (files), or as a number.
Sourcepub fn between(self, min: impl Into<f64>, max: impl Into<f64>) -> Self
pub fn between(self, min: impl Into<f64>, max: impl Into<f64>) -> Self
Between min and max inclusive, measured as min/max do.
Sourcepub fn email(self) -> Self
pub fn email(self) -> Self
An email address: something before a single @, a dotted domain, no spaces.
Sourcepub fn image(self) -> Self
pub fn image(self) -> Self
An uploaded image: PNG, JPEG, GIF or WebP, checked from the file’s content rather than its name.
Sourcepub fn mimes(self, extensions: &[&str]) -> Self
pub fn mimes(self, extensions: &[&str]) -> Self
An uploaded file of one of these types, e.g. &["jpg", "png", "pdf"]
(jpeg counts as jpg). The content decides for the formats Renox can
recognise, the file name for the rest.
Sourcepub fn one_of<V: FieldValue>(self, allowed: &[V]) -> Self
pub fn one_of<V: FieldValue>(self, allowed: &[V]) -> Self
One of the given values (Laravel’s in).
Sourcepub fn confirmed(self, confirmation: &impl FieldValue) -> Self
pub fn confirmed(self, confirmation: &impl FieldValue) -> Self
Equal to its confirmation field, e.g. password and password_confirmation.
Sourcepub fn rule(self, valid: bool, message: impl Into<String>) -> Self
pub fn rule(self, valid: bool, message: impl Into<String>) -> Self
A custom check: fails with message when valid is false.
Sourcepub fn matches(self, pattern: &str) -> Self
pub fn matches(self, pattern: &str) -> Self
The whole text matches pattern (a regular expression; anchor it
with ^…$ to match all of it), e.g. .matches(r"^[A-Z]{2}\d{4}$").
Sourcepub fn digits_between(self, min: usize, max: usize) -> Self
pub fn digits_between(self, min: usize, max: usize) -> Self
Between min and max digits (and nothing else), e.g. a phone number.
Sourcepub fn before(self, limit: impl FieldValue) -> Self
pub fn before(self, limit: impl FieldValue) -> Self
A date before limit (a NaiveDate, NaiveDateTime or DateTime,
or text such as "2026-01-01"), e.g. .before(today) for a birth date.
Sourcepub fn before_or_equal(self, limit: impl FieldValue) -> Self
pub fn before_or_equal(self, limit: impl FieldValue) -> Self
A date on or before limit.
Sourcepub fn after(self, limit: impl FieldValue) -> Self
pub fn after(self, limit: impl FieldValue) -> Self
A date after limit, e.g. .after(self.start) for an end date.
Sourcepub fn after_or_equal(self, limit: impl FieldValue) -> Self
pub fn after_or_equal(self, limit: impl FieldValue) -> Self
A date on or after limit.
Sourcepub fn none_of<V: FieldValue>(self, refused: &[V]) -> Self
pub fn none_of<V: FieldValue>(self, refused: &[V]) -> Self
None of the given values (Laravel’s not_in).
Sourcepub fn alpha_dash(self) -> Self
pub fn alpha_dash(self) -> Self
Letters, digits, - and _, e.g. a username or a slug.
Sourcepub fn starts_with(self, prefixes: &[&str]) -> Self
pub fn starts_with(self, prefixes: &[&str]) -> Self
Starts with one of prefixes, e.g. .starts_with(&["08", "+62"]).
Sourcepub fn ends_with(self, suffixes: &[&str]) -> Self
pub fn ends_with(self, suffixes: &[&str]) -> Self
Ends with one of suffixes, e.g. .ends_with(&["@company.com"]).
Sourcepub fn size(self, size: impl Into<f64>) -> Self
pub fn size(self, size: impl Into<f64>) -> Self
Exactly size characters, items, kilobytes (files), or equal to it as
a number (Laravel’s size).
Sourcepub fn required_without(self, other: &impl FieldValue) -> Self
pub fn required_without(self, other: &impl FieldValue) -> Self
Required when other is empty, e.g. an email when there’s no phone.
Sourcepub fn prohibited_if(self, condition: bool) -> Self
pub fn prohibited_if(self, condition: bool) -> Self
Must be empty when condition holds (Laravel’s prohibited_if), e.g.
no discount code on a gift card order.
Sourcepub fn required_if(self, condition: bool) -> Self
pub fn required_if(self, condition: bool) -> Self
Required when condition holds, e.g.
.required_if(self.kind == "company") for a company name.
Sourcepub fn required_unless(self, condition: bool) -> Self
pub fn required_unless(self, condition: bool) -> Self
Required unless condition holds.
Sourcepub fn required_with(self, other: &impl FieldValue) -> Self
pub fn required_with(self, other: &impl FieldValue) -> Self
Required when other has a value, e.g. a phone number’s country
code when a phone number is given.
Sourcepub fn same(self, other: &str, value: &impl FieldValue) -> Self
pub fn same(self, other: &str, value: &impl FieldValue) -> Self
Equal to another field, named other in the message.
Sourcepub fn different(self, other: &str, value: &impl FieldValue) -> Self
pub fn different(self, other: &str, value: &impl FieldValue) -> Self
Different from another field, named other in the message.
Sourcepub fn gt(self, other: &str, value: &impl FieldValue) -> Self
pub fn gt(self, other: &str, value: &impl FieldValue) -> Self
Greater than another field (Laravel’s gt), named other in the
message: numbers by value (also two texts that both read as
numbers), dates by date, other text by length, lists by items,
files by size, e.g. a maximum price above the minimum. Skipped when
the other field is empty.
Sourcepub fn gte(self, other: &str, value: &impl FieldValue) -> Self
pub fn gte(self, other: &str, value: &impl FieldValue) -> Self
Greater than or equal to another field; see gt.
Sourcepub fn lt(self, other: &str, value: &impl FieldValue) -> Self
pub fn lt(self, other: &str, value: &impl FieldValue) -> Self
Less than another field; see gt.
Sourcepub fn lte(self, other: &str, value: &impl FieldValue) -> Self
pub fn lte(self, other: &str, value: &impl FieldValue) -> Self
Less than or equal to another field; see gt.
Sourcepub fn decimal(self, min: usize, max: usize) -> Self
pub fn decimal(self, min: usize, max: usize) -> Self
A number with min to max decimal places (Laravel’s decimal),
e.g. .decimal(2, 2) for a price typed as 12.50. A text field
keeps what was typed; an f64 field has lost trailing zeros
(12.50 is 12.5), so check prices as text.
Sourcepub fn dimensions(self, limits: &Dimensions) -> Self
pub fn dimensions(self, limits: &Dimensions) -> Self
An uploaded image within limits, e.g.
.dimensions(&Dimensions::new().min_width(400).ratio(16, 9)); see
Dimensions. A file that isn’t an image fails.
Sourcepub fn prohibited(self) -> Self
pub fn prohibited(self) -> Self
Must be empty (Laravel’s prohibited), e.g. a field only an admin
may send, checked for everyone else.
Sourcepub fn prohibited_unless(self, condition: bool) -> Self
pub fn prohibited_unless(self, condition: bool) -> Self
Must be empty unless condition holds.
Sourcepub fn prohibits(self, other: &str, value: &impl FieldValue) -> Self
pub fn prohibits(self, other: &str, value: &impl FieldValue) -> Self
When this field has a value, other must be empty (Laravel’s
prohibits), e.g. a coupon code and a gift card can’t both be used.
Sourcepub fn required_with_all(self, others: &[&dyn FieldValue]) -> Self
pub fn required_with_all(self, others: &[&dyn FieldValue]) -> Self
Required when every one of others has a value.
Sourcepub fn required_without_all(self, others: &[&dyn FieldValue]) -> Self
pub fn required_without_all(self, others: &[&dyn FieldValue]) -> Self
Required when none of others has a value, e.g. one way to reach
the customer at least.
Sourcepub fn min_digits(self, min: usize) -> Self
pub fn min_digits(self, min: usize) -> Self
An integer of at least min digits.
Sourcepub fn max_digits(self, max: usize) -> Self
pub fn max_digits(self, max: usize) -> Self
An integer of at most max digits.
Sourcepub fn multiple_of(self, step: impl Into<f64>) -> Self
pub fn multiple_of(self, step: impl Into<f64>) -> Self
A multiple of step, e.g. .multiple_of(500) for amounts in
steps of 500, or .multiple_of(0.25).
Sourcepub fn integer(self) -> Self
pub fn integer(self) -> Self
A whole number: a number field without a fraction, or text that reads as one.
Sourcepub fn mac_address(self) -> Self
pub fn mac_address(self) -> Self
A MAC address: 00:1A:2B:3C:4D:5E, with - as well, or
001A.2B3C.4D5E.
Sourcepub fn doesnt_start_with(self, prefixes: &[&str]) -> Self
pub fn doesnt_start_with(self, prefixes: &[&str]) -> Self
Doesn’t start with any of prefixes.
Sourcepub fn doesnt_end_with(self, suffixes: &[&str]) -> Self
pub fn doesnt_end_with(self, suffixes: &[&str]) -> Self
Doesn’t end with any of suffixes.
Sourcepub fn not_matches(self, pattern: &str) -> Self
pub fn not_matches(self, pattern: &str) -> Self
The text does not match pattern (Laravel’s not_regex).
Sourcepub fn accepted_if(self, condition: bool) -> Self
pub fn accepted_if(self, condition: bool) -> Self
A checkbox that must be ticked when condition holds.
Sourcepub fn declined(self) -> Self
pub fn declined(self) -> Self
Must be declined: an unticked checkbox (false), or no, off,
0 or false, e.g. “Don’t share my data” answered no.
Sourcepub fn declined_if(self, condition: bool) -> Self
pub fn declined_if(self, condition: bool) -> Self
Must be declined when condition holds; see declined.
Sourcepub fn password(self, policy: &Password) -> Self
pub fn password(self, policy: &Password) -> Self
The value meets policy (length, letters, mixed case, numbers,
symbols); see Password.
Sourcepub fn current_password(self) -> Self
pub fn current_password(self) -> Self
The logged-in user’s password (Laravel’s current_password), e.g.
before changing an email address. Checked last, once the other
rules pass; it fails when no one is logged in. Needs
Validator::finish_for, which Valid<T> uses.
Sourcepub fn unique(self, table: &str, column: &str) -> Self
pub fn unique(self, table: &str, column: &str) -> Self
No row in table has this value in column.
Sourcepub fn ignore(self, id: impl ToDbValue) -> Self
pub fn ignore(self, id: impl ToDbValue) -> Self
Skips the row with this id in the preceding unique, for updates:
.unique("products", "sku").ignore(product.id), whatever the key’s
type (i64, Ulid, Uuid, String).
Sourcepub fn exists(self, table: &str, column: &str) -> Self
pub fn exists(self, table: &str, column: &str) -> Self
Some row in table has this value in column.
Sourcepub fn where_eq(self, column: &str, value: impl ToDbValue) -> Self
pub fn where_eq(self, column: &str, value: impl ToDbValue) -> Self
Only rows where column = value count for the preceding unique or
exists, e.g. the current team’s: SKUs are unique per team.
fn rules(&self, v: &mut Validator) {
v.field("sku", &self.sku)
.unique("products", "sku")
.ignore(self.id)
.where_eq("team_id", self.team_id)
.where_null("deleted_at"); // soft-deleted rows don't count
v.field("category_id", &self.category_id)
.exists("categories", "id")
.where_eq("team_id", self.team_id); // not another team's category
}Sourcepub fn where_null(self, column: &str) -> Self
pub fn where_null(self, column: &str) -> Self
Only rows where column is null count (e.g. deleted_at).
Sourcepub fn where_not_null(self, column: &str) -> Self
pub fn where_not_null(self, column: &str) -> Self
Only rows where column is not null count.
Auto Trait Implementations§
impl<'v> !UnwindSafe for Field<'v>
impl<'v> Freeze for Field<'v>
impl<'v> RefUnwindSafe for Field<'v>
impl<'v> Send for Field<'v>
impl<'v> Sync for Field<'v>
impl<'v> Unpin for Field<'v>
impl<'v> UnsafeUnpin for Field<'v>
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
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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