Skip to main content

prepare_text_validator

Function prepare_text_validator 

Source
pub fn prepare_text_validator<V, M>(
    validator: V,
    map_error: M,
) -> Arc<dyn PreparedValidator> ⓘ
where V: Validator<str, ()> + Send + Sync + 'static, M: Fn(V::Error) -> ViolationDraft + Send + Sync + 'static,
Expand description

Prepares a text validator using a domain-error mapper.

The returned adapter rejects non-text erased inputs and converts each domain error with map_error; callers should ensure the mapper does not retain raw input in the resulting draft.

§Type Parameters

  • V: Validator of borrowed text with unit context.
  • M: Mapper from the validator error to a safe violation draft.

§Panics

This function does not panic. The prepared adapter reports an input-shape error if it receives a non-text value.

§Parameters

  • validator: Thread-safe validator for borrowed text with unit context.
  • map_error: Converts each domain error to safe violation metadata.

§Returns

A shared prepared adapter that checks for text input before validation.

Examples found in repository?
examples/local_registry.rs (lines 70-72)
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}