#[non_exhaustive]pub struct Violation { /* private fields */ }Expand description
A single instance where a validation rule was not met.
Implementations§
Source§impl Violation
impl Violation
Sourcepub fn new(
field_path: impl Into<String>,
rule_id: impl Into<String>,
message: impl Into<String>,
) -> Self
pub fn new( field_path: impl Into<String>, rule_id: impl Into<String>, message: impl Into<String>, ) -> Self
Create a violation with the given field path, rule identifier, and message.
The rule_path is set equal to rule_id. Enrichment fields
(field_descriptor, field_value, rule_descriptor, rule_value) are
left as None — they are populated only by the runtime validator.
Sourcepub fn new_constraint(
field_path: impl Into<String>,
rule_id: impl Into<String>,
rule_path: impl Into<String>,
) -> Self
pub fn new_constraint( field_path: impl Into<String>, rule_id: impl Into<String>, rule_path: impl Into<String>, ) -> Self
Create a violation for a standard constraint where rule_path (the proto
field path, e.g. "string.email") may differ from rule_id (the
constraint identifier, e.g. "string.email_empty").
The message field is intentionally left empty per the conformance spec.
Enrichment fields (field_descriptor, field_value, rule_descriptor,
rule_value) are left as None.
Sourcepub fn to_proto(&self) -> Violation
pub fn to_proto(&self) -> Violation
Serialize this violation into the wire-compatible protobuf message.
Sourcepub fn field_path(&self) -> String
pub fn field_path(&self) -> String
Returns the dot-separated field path where this violation occurred.
Sourcepub fn field_descriptor(&self) -> Option<&FieldDescriptor>
pub fn field_descriptor(&self) -> Option<&FieldDescriptor>
Returns the field descriptor for the violated field, if available.
Sourcepub fn field_value(&self) -> Option<&Value>
pub fn field_value(&self) -> Option<&Value>
Returns the field value that failed validation, when available.
Sourcepub fn rule_descriptor(&self) -> Option<&FieldDescriptor>
pub fn rule_descriptor(&self) -> Option<&FieldDescriptor>
Returns the descriptor for the violated rule field, when available.
Sourcepub fn rule_value(&self) -> Option<&Value>
pub fn rule_value(&self) -> Option<&Value>
Returns the value of the violated rule field, when available.
Sourcepub fn set_field_path(&mut self, field_path: impl Into<String>)
pub fn set_field_path(&mut self, field_path: impl Into<String>)
Sets the field path.
Sourcepub fn set_rule_path(&mut self, rule_path: impl Into<String>)
pub fn set_rule_path(&mut self, rule_path: impl Into<String>)
Sets the rule path.
Sourcepub fn set_rule_id(&mut self, rule_id: impl Into<String>)
pub fn set_rule_id(&mut self, rule_id: impl Into<String>)
Sets the machine-readable rule identifier.
Sourcepub fn set_message(&mut self, message: impl Into<String>)
pub fn set_message(&mut self, message: impl Into<String>)
Sets the human-readable violation message.
Sourcepub fn without_rule_path(self) -> Self
pub fn without_rule_path(self) -> Self
Strip the rule path so proto.rule is None.
Used for violations where only rule_id should be emitted
(e.g. oneof, message-level CEL).
Sourcepub fn mark_for_key(&mut self)
pub fn mark_for_key(&mut self)
Mark this violation as caused by a map key (rather than a value).
Set by the runtime map evaluator on every key-rule violation and by
generated validators when iterating map-key constraints — preserves
the for_key field on the wire-level Violation proto.
Sourcepub fn for_key(&self) -> Option<bool>
pub fn for_key(&self) -> Option<bool>
Returns whether this violation was caused by a map key (rather than a value).
None when the field is unset on the wire (the common case for
non-map-key violations); Some(true) after Violation::mark_for_key.
Sourcepub fn prepend_field_path(&mut self, parent: &str)
pub fn prepend_field_path(&mut self, parent: &str)
Prepend a parent field path element.
Sourcepub fn prepend_index(&mut self, parent: &str, index: u64)
pub fn prepend_index(&mut self, parent: &str, index: u64)
Prepend a parent field path with a repeated index subscript:
parent[index].<existing>.
Sourcepub fn prepend_string_key(&mut self, parent: &str, key: &str)
pub fn prepend_string_key(&mut self, parent: &str, key: &str)
Prepend a parent field path with a string-keyed map subscript:
parent["key"].<existing>. The key is JSON-escaped on rendering,
matching the canonical runtime format for map paths.
Sourcepub fn prepend_int_key(&mut self, parent: &str, key: i64)
pub fn prepend_int_key(&mut self, parent: &str, key: i64)
Prepend a parent field path with a signed-integer-keyed map subscript:
parent[key].<existing>.
Sourcepub fn prepend_uint_key(&mut self, parent: &str, key: u64)
pub fn prepend_uint_key(&mut self, parent: &str, key: u64)
Prepend a parent field path with an unsigned-integer-keyed map subscript:
parent[key].<existing>.
Sourcepub fn prepend_bool_key(&mut self, parent: &str, key: bool)
pub fn prepend_bool_key(&mut self, parent: &str, key: bool)
Prepend a parent field path with a bool-keyed map subscript:
parent[true].<existing> or parent[false].<existing>.
Sourcepub fn prepend_rule_path(&mut self, parent: &str)
pub fn prepend_rule_path(&mut self, parent: &str)
Prepend a parent rule path element.
Used by generated validators to splice container-rule path
segments (e.g. repeated.items, map.keys, map.values) onto
item-level violations so the final rule_path matches the
runtime emission.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Violation
impl RefUnwindSafe for Violation
impl Send for Violation
impl Sync for Violation
impl Unpin for Violation
impl UnsafeUnpin for Violation
impl UnwindSafe for Violation
Blanket Implementations§
Source§impl<T> AnyExt for T
impl<T> AnyExt for T
Source§fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
T behind referenceSource§fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
T behind mutable referenceSource§fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
T behind Rc pointerSource§fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
T behind Arc pointerSource§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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
fn coerce_rc_to(self: Rc<X>) -> Rc<T>
fn coerce_box_to(self: Box<X>) -> Box<T>
fn coerce_ref_to(&self) -> &T
fn coerce_mut_to(&mut self) -> &mut T
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request