Skip to main content

ValidationValue

Enum ValidationValue 

Source
#[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.

Tuple Fields

§0: &'a str

Raw text borrowed only for the duration of validation.

§

Typed(&'a dyn Any)

A borrowed value with an exact concrete type available through Any.

Tuple Fields

§0: &'a dyn Any

Raw typed value borrowed only for the duration of validation.

§

Missing

An explicitly expanded optional value which is absent.

Implementations§

Source§

impl<'a> ValidationValue<'a>

Source

pub fn input_type(self) -> Option<InputType>

Returns the concrete input shape, if one is present.

§Returns

Returns None only for Self::Missing.

Source

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

pub const fn is_missing(self) -> bool

Returns whether this value is the explicit missing marker.

§Returns

Returns true only for Self::Missing.

Source

pub fn typed<T: 'static>(self) -> Option<&'a T>

Attempts to borrow the value as its exact concrete type.

§Type Parameters
  • T: Requested concrete type, which must be 'static for Any.
§Returns

Returns None for text, missing, and differently typed values.

Trait Implementations§

Source§

impl<'a> Clone for ValidationValue<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for ValidationValue<'a>

Source§

impl Debug for ValidationValue<'_>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats only the value shape and always redacts raw input.

§Parameters
  • formatter: Destination used to write the redacted value shape.
§Returns

Returns Ok(()) when formatting succeeds, or the formatter’s error otherwise.

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> Forget 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> 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.