Skip to main content

Field

Struct Field 

Source
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<'_>

Source

pub fn label(self, label: &str) -> Self

The name used in messages, e.g. .label("sale price").

Source

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.

Source

pub fn required(self) -> Self

Fails when the value is missing: None, or text that is blank after trimming.

Source

pub fn min(self, min: impl Into<f64>) -> Self

At least min characters, items, kilobytes (files), or as a number.

Source

pub fn max(self, max: impl Into<f64>) -> Self

At most max characters, items, kilobytes (files), or as a number.

Source

pub fn between(self, min: impl Into<f64>, max: impl Into<f64>) -> Self

Between min and max inclusive, measured as min/max do.

Source

pub fn email(self) -> Self

An email address: something before a single @, a dotted domain, no spaces.

Source

pub fn url(self) -> Self

An http:// or https:// URL with a host and no spaces.

Source

pub fn image(self) -> Self

An uploaded image: PNG, JPEG, GIF or WebP, checked from the file’s content rather than its name.

Source

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.

Source

pub fn one_of<V: FieldValue>(self, allowed: &[V]) -> Self

One of the given values (Laravel’s in).

Source

pub fn confirmed(self, confirmation: &impl FieldValue) -> Self

Equal to its confirmation field, e.g. password and password_confirmation.

Source

pub fn accepted(self) -> Self

A checkbox that must be ticked.

Source

pub fn rule(self, valid: bool, message: impl Into<String>) -> Self

A custom check: fails with message when valid is false.

Source

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}$").

Source

pub fn digits(self, n: usize) -> Self

Exactly n digits (and nothing else), e.g. a PIN.

Source

pub fn digits_between(self, min: usize, max: usize) -> Self

Between min and max digits (and nothing else), e.g. a phone number.

Source

pub fn date(self) -> Self

A date (2026-10-01) or a date and time (2026-10-01T10:30).

Source

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.

Source

pub fn before_or_equal(self, limit: impl FieldValue) -> Self

A date on or before limit.

Source

pub fn after(self, limit: impl FieldValue) -> Self

A date after limit, e.g. .after(self.start) for an end date.

Source

pub fn after_or_equal(self, limit: impl FieldValue) -> Self

A date on or after limit.

Source

pub fn none_of<V: FieldValue>(self, refused: &[V]) -> Self

None of the given values (Laravel’s not_in).

Source

pub fn alpha(self) -> Self

Letters only (any language’s: é, ü, ß count).

Source

pub fn alpha_num(self) -> Self

Letters and digits only.

Source

pub fn alpha_dash(self) -> Self

Letters, digits, - and _, e.g. a username or a slug.

Source

pub fn lowercase(self) -> Self

No uppercase letters.

Source

pub fn uppercase(self) -> Self

No lowercase letters.

Source

pub fn starts_with(self, prefixes: &[&str]) -> Self

Starts with one of prefixes, e.g. .starts_with(&["08", "+62"]).

Source

pub fn ends_with(self, suffixes: &[&str]) -> Self

Ends with one of suffixes, e.g. .ends_with(&["@company.com"]).

Source

pub fn uuid(self) -> Self

A UUID (8-4-4-4-12 hexadecimal digits).

Source

pub fn ip(self) -> Self

An IPv4 or IPv6 address.

Source

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).

Source

pub fn required_without(self, other: &impl FieldValue) -> Self

Required when other is empty, e.g. an email when there’s no phone.

Source

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.

Source

pub fn required_if(self, condition: bool) -> Self

Required when condition holds, e.g. .required_if(self.kind == "company") for a company name.

Source

pub fn required_unless(self, condition: bool) -> Self

Required unless condition holds.

Source

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.

Source

pub fn same(self, other: &str, value: &impl FieldValue) -> Self

Equal to another field, named other in the message.

Source

pub fn different(self, other: &str, value: &impl FieldValue) -> Self

Different from another field, named other in the message.

Source

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.

Source

pub fn gte(self, other: &str, value: &impl FieldValue) -> Self

Greater than or equal to another field; see gt.

Source

pub fn lt(self, other: &str, value: &impl FieldValue) -> Self

Less than another field; see gt.

Source

pub fn lte(self, other: &str, value: &impl FieldValue) -> Self

Less than or equal to another field; see gt.

Source

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.

Source

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.

Source

pub fn prohibited(self) -> Self

Must be empty (Laravel’s prohibited), e.g. a field only an admin may send, checked for everyone else.

Source

pub fn prohibited_unless(self, condition: bool) -> Self

Must be empty unless condition holds.

Source

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.

Source

pub fn required_with_all(self, others: &[&dyn FieldValue]) -> Self

Required when every one of others has a value.

Source

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.

Source

pub fn min_digits(self, min: usize) -> Self

An integer of at least min digits.

Source

pub fn max_digits(self, max: usize) -> Self

An integer of at most max digits.

Source

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).

Source

pub fn numeric(self) -> Self

A number: a number field, or text that reads as one (12, -3.5).

Source

pub fn integer(self) -> Self

A whole number: a number field without a fraction, or text that reads as one.

Source

pub fn json(self) -> Self

Valid JSON text, e.g. a settings field edited by hand.

Source

pub fn ulid(self) -> Self

A ULID (26 characters of Crockford’s base 32).

Source

pub fn timezone(self) -> Self

An IANA time zone name, e.g. Asia/Jakarta, or UTC.

Source

pub fn mac_address(self) -> Self

A MAC address: 00:1A:2B:3C:4D:5E, with - as well, or 001A.2B3C.4D5E.

Source

pub fn ascii(self) -> Self

ASCII characters only.

Source

pub fn hex_color(self) -> Self

A hex colour: #RGB, #RGBA, #RRGGBB or #RRGGBBAA.

Source

pub fn doesnt_start_with(self, prefixes: &[&str]) -> Self

Doesn’t start with any of prefixes.

Source

pub fn doesnt_end_with(self, suffixes: &[&str]) -> Self

Doesn’t end with any of suffixes.

Source

pub fn not_matches(self, pattern: &str) -> Self

The text does not match pattern (Laravel’s not_regex).

Source

pub fn accepted_if(self, condition: bool) -> Self

A checkbox that must be ticked when condition holds.

Source

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.

Source

pub fn declined_if(self, condition: bool) -> Self

Must be declined when condition holds; see declined.

Source

pub fn password(self, policy: &Password) -> Self

The value meets policy (length, letters, mixed case, numbers, symbols); see Password.

Source

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.

Source

pub fn apply(self, rule: &impl Rule) -> Self

A reusable rule; see Rule.

Source

pub fn unique(self, table: &str, column: &str) -> Self

No row in table has this value in column.

Source

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).

Source

pub fn exists(self, table: &str, column: &str) -> Self

Some row in table has this value in column.

Source

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
}
Source

pub fn where_null(self, column: &str) -> Self

Only rows where column is null count (e.g. deleted_at).

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Fake for T

Source§

fn fake<U>(&self) -> U
where Self: FakeBase<U>,

Source§

fn fake_with_rng<U, R>(&self, rng: &mut R) -> U
where R: RngExt + ?Sized, Self: FakeBase<U>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more