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
impl ViolationDraft
Sourcepub fn new(code: ViolationCode) -> Self
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 }Sourcepub fn with_path(self, path: ValidationPath) -> Self
pub fn with_path(self, path: ValidationPath) -> Self
Sourcepub fn with_param(self, name: &'static str, value: ViolationParam) -> Self
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 withname, 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
impl Debug for ViolationDraft
impl Eq for ViolationDraft
Source§impl PartialEq for ViolationDraft
impl PartialEq for ViolationDraft
impl StructuralPartialEq for ViolationDraft
Auto Trait Implementations§
impl Forget for ViolationDraft
impl Freeze for ViolationDraft
impl Move for ViolationDraft
impl RefUnwindSafe for ViolationDraft
impl Send for ViolationDraft
impl Sync for ViolationDraft
impl Unpin for ViolationDraft
impl UnsafeUnpin for ViolationDraft
impl UnwindSafe for ViolationDraft
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