#[non_exhaustive]pub enum ValidationValue<'a> {
Text(&'a str),
Typed(&'a dyn Any),
Missing,
}Expand description
A value view that deliberately avoids implicit stringification and cloning.
§Type Parameters
'a: Lifetime for which the borrowed input remains available.
§Examples
use qubit_validator::ValidationValue;
let value = ValidationValue::Text("hello");
assert_eq!(value.as_text(), Some("hello"));
assert!(!value.is_missing());Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Text(&'a str)
A borrowed UTF-8 string slice.
Typed(&'a dyn Any)
A borrowed value with an exact concrete type available through Any.
Missing
An explicitly expanded optional value which is absent.
Implementations§
Source§impl<'a> ValidationValue<'a>
impl<'a> ValidationValue<'a>
Sourcepub fn input_type(self) -> Option<InputType>
pub fn input_type(self) -> Option<InputType>
Sourcepub const fn as_text(self) -> Option<&'a str>
pub const fn as_text(self) -> Option<&'a str>
Returns the text view when this is a text value.
§Returns
Returns None for typed and missing values.
Examples found in repository?
examples/local_registry.rs (line 101)
96 fn validate(
97 &self,
98 _: ValidationValue<'_>,
99 context: &BoundValidationContext<'_>,
100 ) -> Result<PreparedOutcome, ExecutionError> {
101 let valid = context.value(0)?.as_text() == Some("minimum") && context.value(1)?.as_text() == Some("maximum");
102 Ok(if valid {
103 PreparedOutcome::Valid
104 } else {
105 PreparedOutcome::Invalid(vec![ViolationDraft::new(ViolationCode::new(
106 "text.dependencies_mismatch",
107 ))])
108 })
109 }Sourcepub const fn is_missing(self) -> bool
pub const fn is_missing(self) -> bool
Returns whether this value is the explicit missing marker.
§Returns
Returns true only for Self::Missing.
Trait Implementations§
Source§impl<'a> Clone for ValidationValue<'a>
impl<'a> Clone for ValidationValue<'a>
impl<'a> Copy for ValidationValue<'a>
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for ValidationValue<'a>
impl<'a> !Send for ValidationValue<'a>
impl<'a> !Sync for ValidationValue<'a>
impl<'a> !UnwindSafe for ValidationValue<'a>
impl<'a> Freeze for ValidationValue<'a>
impl<'a> Unpin for ValidationValue<'a>
impl<'a> UnsafeUnpin for ValidationValue<'a>
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