Skip to main content

ViolationDraft

Struct ViolationDraft 

Source
pub struct ViolationDraft { /* private fields */ }
Expand description

A structured violation draft without a rule identity.

§Examples

use qubit_validator::{ViolationCode, ViolationDraft, ViolationParam};

let draft = ViolationDraft::new(ViolationCode::new("text.too_short"))
    .with_param("minimum", ViolationParam::Unsigned(3));
assert!(format!("{draft:?}").contains("text.too_short"));
assert!(!format!("{draft:?}").contains("secret input"));

Implementations§

Source§

impl ViolationDraft

Source

pub fn new(code: ViolationCode) -> Self

Creates a draft at the root path using a stable violation code.

§Parameters
  • code: Program-declared code that identifies the validation failure.
§Returns

A draft with no parameters and an empty root path.

Examples found in repository?
examples/local_registry.rs (line 71)
69fn prepare_non_blank(_reader: &mut ArgumentReader<'_>) -> Result<Arc<dyn PreparedValidator>, BindError> {
70    Ok(prepare_text_validator(NonBlank, |_| {
71        ViolationDraft::new(ViolationCode::new("text.blank"))
72    }))
73}
74
75static SIGNATURES: &[ValidatorSignature] = &[ValidatorSignature::new(InputType::Text, &[], prepare_non_blank)];
76static DESCRIPTOR: ValidatorDescriptor = ValidatorDescriptor::new(SIGNATURES);
77
78#[cfg(feature = "inventory")]
79register_validator!(id = "text.non_blank.global", descriptor = &DESCRIPTOR);
80
81static DEPENDENCIES: &[DependencySpec] = &[
82    DependencySpec::new("minimum", InputType::Text, false),
83    DependencySpec::new("maximum", InputType::Text, false),
84];
85
86struct CheckDependencySlots;
87
88impl PreparedValidator for CheckDependencySlots {
89    fn input_type(&self) -> InputType {
90        InputType::Text
91    }
92    fn dependency_specs(&self) -> &'static [DependencySpec] {
93        DEPENDENCIES
94    }
95
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 fn with_path(self, path: ValidationPath) -> Self

Replaces the relative path attached to this violation draft.

§Parameters
  • path: Structured location relative to the current validation target.
§Returns

The draft with path stored for later report prefixing.

Source

pub fn with_param(self, name: &'static str, value: ViolationParam) -> Self

Adds or replaces a structured parameter by its declared name.

The type restricts representation but cannot prove provenance. Supply only program-declared tokens or rule configuration values, never rejected input or sensitive values derived from it.

§Parameters
  • name: Static name declared by the application for this parameter.
  • value: Structured value to associate with name, subject to the caller’s provenance and redaction responsibility.
§Returns

The draft with the parameter inserted; an existing value with the same name is replaced.

Trait Implementations§

Source§

impl Debug for ViolationDraft

Source§

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

Formats only safe metadata and the parameter count.

Source§

impl Eq for ViolationDraft

Source§

impl PartialEq for ViolationDraft

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ViolationDraft

Auto Trait Implementations§

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