pub enum InputValue {
Null,
Bool(bool),
Number(Number),
String(String),
File(UploadedFile),
Array(Vec<InputValue>),
Object(IndexMap<String, InputValue>),
}Expand description
A submitted request value: a JSON or form value, or an UploadedFile.
Validation rules and typed decoding read the same InputValue tree, so text fields and
uploaded files share one structure without separate path lookups.
use laravel::validation::{Field, InputValue, RuleError, ValidationRule};
struct ValidCsv;
impl ValidationRule for ValidCsv {
async fn validate(&self, field: &Field<'_>) -> Result<(), RuleError> {
let Some(file) = field.value.and_then(InputValue::as_file) else {
return Err(field.reject("The :attribute field must be a CSV file."));
};
if file.client_extension() != Some("csv") {
return Err(field.reject("The :attribute file must have a .csv extension."));
}
Ok(())
}
}Variants§
Null
A null value, including an empty string converted by
ConvertEmptyStringsToNull.
Bool(bool)
A JSON boolean.
Number(Number)
A JSON number.
String(String)
A text value from a query parameter, form field, or JSON string.
File(UploadedFile)
A file uploaded with a multipart/form-data request.
Array(Vec<InputValue>)
A list of submitted values, such as a JSON array or tags[] form fields.
Object(IndexMap<String, InputValue>)
A nested object of submitted values, such as a JSON object or user[name] form fields.
Implementations§
Source§impl InputValue
impl InputValue
Sourcepub const fn is_null(&self) -> bool
pub const fn is_null(&self) -> bool
Returns whether this value is InputValue::Null.
Sourcepub const fn is_bool(&self) -> bool
pub const fn is_bool(&self) -> bool
Returns whether this value is InputValue::Bool.
Sourcepub const fn is_number(&self) -> bool
pub const fn is_number(&self) -> bool
Returns whether this value is InputValue::Number.
Sourcepub const fn is_string(&self) -> bool
pub const fn is_string(&self) -> bool
Returns whether this value is InputValue::String.
Sourcepub const fn is_file(&self) -> bool
pub const fn is_file(&self) -> bool
Returns whether this value is InputValue::File.
Sourcepub const fn is_array(&self) -> bool
pub const fn is_array(&self) -> bool
Returns whether this value is InputValue::Array.
Sourcepub const fn is_object(&self) -> bool
pub const fn is_object(&self) -> bool
Returns whether this value is InputValue::Object.
Sourcepub const fn as_bool(&self) -> Option<bool>
pub const fn as_bool(&self) -> Option<bool>
Returns the boolean if this value is InputValue::Bool.
Sourcepub const fn as_number(&self) -> Option<&Number>
pub const fn as_number(&self) -> Option<&Number>
Returns the number if this value is InputValue::Number.
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Returns the string slice if this value is InputValue::String.
Sourcepub const fn as_file(&self) -> Option<&UploadedFile>
pub const fn as_file(&self) -> Option<&UploadedFile>
Returns the uploaded file if this value is InputValue::File.
Sourcepub fn as_array(&self) -> Option<&[InputValue]>
pub fn as_array(&self) -> Option<&[InputValue]>
Returns the slice of items if this value is InputValue::Array.
Sourcepub const fn as_object(&self) -> Option<&IndexMap<String, InputValue>>
pub const fn as_object(&self) -> Option<&IndexMap<String, InputValue>>
Returns the map of entries if this value is InputValue::Object.
Sourcepub fn get(&self, key: &str) -> Option<&InputValue>
pub fn get(&self, key: &str) -> Option<&InputValue>
Returns the entry under key if this value is InputValue::Object.
Trait Implementations§
Source§impl Clone for InputValue
impl Clone for InputValue
Source§fn clone(&self) -> InputValue
fn clone(&self) -> InputValue
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 InputValue
impl Debug for InputValue
Source§impl From<&str> for InputValue
impl From<&str> for InputValue
Source§fn from(text: &str) -> InputValue
fn from(text: &str) -> InputValue
Source§impl From<String> for InputValue
impl From<String> for InputValue
Source§fn from(text: String) -> InputValue
fn from(text: String) -> InputValue
Source§impl From<UploadedFile> for InputValue
impl From<UploadedFile> for InputValue
Source§fn from(file: UploadedFile) -> InputValue
fn from(file: UploadedFile) -> InputValue
Source§impl From<Value> for InputValue
impl From<Value> for InputValue
Source§fn from(value: Value) -> InputValue
fn from(value: Value) -> InputValue
Source§impl From<bool> for InputValue
impl From<bool> for InputValue
Source§fn from(value: bool) -> InputValue
fn from(value: bool) -> InputValue
Auto Trait Implementations§
impl Forget for InputValue
impl Freeze for InputValuewhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
*const ArcInner<Stored> is !null: Freeze,
PhantomData<ArcInner<Stored>>: Freeze,
PhantomData<InputValue>: Freeze,
PhantomData<usize>: Freeze,
PhantomData<Bucket<String, InputValue>>: Freeze,
impl Move for InputValue
impl RefUnwindSafe for InputValue
impl Send for InputValue
impl Sync for InputValue
impl Unpin for InputValue
impl UnsafeUnpin for InputValuewhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const ArcInner<Stored> is !null: UnsafeUnpin,
PhantomData<ArcInner<Stored>>: UnsafeUnpin,
PhantomData<InputValue>: UnsafeUnpin,
PhantomData<usize>: UnsafeUnpin,
PhantomData<Bucket<String, InputValue>>: UnsafeUnpin,
impl UnwindSafe for InputValue
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