Skip to main content

Rule

Trait Rule 

Source
pub trait Rule<T: ?Sized>:
    Debug
    + Send
    + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn validate(&self, value: &T) -> Option<RefineRejection>;
}
Expand description

Object-safe extension point stored boxed (Box<dyn Rule<T>>) inside schemas (SC-7).

Rules observe post-normalization values and run strictly after builtin checks. Sync-only by signature (RF-3): no future/async types exist here.

The Send + Sync supertraits guarantee that every erased view (Box<dyn Rule<T>>, &dyn Rule<T>, Arc<dyn Rule<T>>) is usable from multiple threads. This is a breaking contract for hypothetical custom impls holding !Send/!Sync state; pre-1.0 this may change in a minor release.

Required Methods§

Source

fn name(&self) -> &str

Stable identifier for the rule, used for diagnostics and Debug output only. In v0 it is NOT embedded in issue params and NOT surfaced via shape(); surfacing remains a candidate future contract change. Borrowed from the rule itself so generated names need no 'static interning.

Source

fn validate(&self, value: &T) -> Option<RefineRejection>

Returns rejection data on failure; None on pass.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: ?Sized> Rule<T> for ClosureRule<T>