Skip to main content

Violation

Struct Violation 

Source
#[non_exhaustive]
pub struct Violation { /* private fields */ }
Expand description

A single instance where a validation rule was not met.

Implementations§

Source§

impl Violation

Source

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.

Source

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.

Source

pub fn to_proto(&self) -> Violation

Serialize this violation into the wire-compatible protobuf message.

Source

pub fn field_path(&self) -> String

Returns the dot-separated field path where this violation occurred.

Source

pub fn rule_path(&self) -> String

Returns the dot-separated rule path that was violated.

Source

pub fn rule_id(&self) -> &str

Returns the machine-readable constraint identifier.

Source

pub fn message(&self) -> &str

Returns the human-readable violation message.

Source

pub fn field_descriptor(&self) -> Option<&FieldDescriptor>

Returns the field descriptor for the violated field, if available.

Source

pub fn field_value(&self) -> Option<&Value>

Returns the field value that failed validation, when available.

Source

pub fn rule_descriptor(&self) -> Option<&FieldDescriptor>

Returns the descriptor for the violated rule field, when available.

Source

pub fn rule_value(&self) -> Option<&Value>

Returns the value of the violated rule field, when available.

Source

pub fn set_field_path(&mut self, field_path: impl Into<String>)

Sets the field path.

Source

pub fn set_rule_path(&mut self, rule_path: impl Into<String>)

Sets the rule path.

Source

pub fn set_rule_id(&mut self, rule_id: impl Into<String>)

Sets the machine-readable rule identifier.

Source

pub fn set_message(&mut self, message: impl Into<String>)

Sets the human-readable violation message.

Source

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

Source

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.

Source

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.

Source

pub fn prepend_field_path(&mut self, parent: &str)

Prepend a parent field path element.

Source

pub fn prepend_index(&mut self, parent: &str, index: u64)

Prepend a parent field path with a repeated index subscript: parent[index].<existing>.

Source

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.

Source

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

Source

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

Source

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

Source

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§

Source§

impl Clone for Violation

Source§

fn clone(&self) -> Violation

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 Debug for Violation

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for Violation

Source§

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

Formats the value using the given formatter. Read more

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> AnyExt for T
where T: Any + ?Sized,

Source§

fn downcast_ref<T>(this: &Self) -> Option<&T>
where T: Any,

Attempts to downcast this to T behind reference
Source§

fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>
where T: Any,

Attempts to downcast this to T behind mutable reference
Source§

fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>
where T: Any,

Attempts to downcast this to T behind Rc pointer
Source§

fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>
where T: Any,

Attempts to downcast this to T behind Arc pointer
Source§

fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>
where T: Any,

Attempts to downcast this to T behind Box pointer
Source§

fn downcast_move<T>(this: Self) -> Option<T>
where T: Any, Self: Sized,

Attempts to downcast owned Self to T, useful only in generic context as a workaround for specialization
Source§

impl<T> AsDebug for T
where T: Debug,

Source§

fn as_debug(&self) -> &dyn Debug

Returns self as a &dyn Debug trait object.
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, X> CoerceTo<T> for X
where T: CoerceFrom<X> + ?Sized,

Source§

fn coerce_rc_to(self: Rc<X>) -> Rc<T>

Source§

fn coerce_box_to(self: Box<X>) -> Box<T>

Source§

fn coerce_ref_to(&self) -> &T

Source§

fn coerce_mut_to(&mut self) -> &mut T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more