pub struct ValidationConfig {
pub character_limits: Option<CharacterLimits>,
pub pattern_filters: Option<PatternFilters>,
pub display_mask: Option<DisplayMask>,
pub custom_formatter: Option<Arc<dyn CustomFormatter + Send + Sync>>,
pub allowed_values: Option<AllowedValues>,
pub external_validation_enabled: bool,
pub external_validation: Option<()>,
}Expand description
Main validation configuration for a field
Fields§
§character_limits: Option<CharacterLimits>Character limit configuration
pattern_filters: Option<PatternFilters>Pattern filtering configuration
display_mask: Option<DisplayMask>User-defined display mask for visual formatting
custom_formatter: Option<Arc<dyn CustomFormatter + Send + Sync>>Optional: user-provided custom formatter (feature 4)
allowed_values: Option<AllowedValues>Optional: restrict the field to one of exact allowed values (or empty)
external_validation_enabled: boolEnable external validation indicator UI (feature 5)
external_validation: Option<()>Implementations§
Source§impl ValidationConfig
impl ValidationConfig
Sourcepub fn run_custom_formatter(
&self,
raw: &str,
) -> Option<(String, Arc<dyn PositionMapper>, Option<String>)>
pub fn run_custom_formatter( &self, raw: &str, ) -> Option<(String, Arc<dyn PositionMapper>, Option<String>)>
If a custom formatter is configured, run it and return the formatted text, the position mapper and an optional warning message.
Returns None when no custom formatter is configured.
Sourcepub fn new() -> ValidationConfig
pub fn new() -> ValidationConfig
Create a new empty validation configuration
Sourcepub fn with_max_length(max_length: usize) -> ValidationConfig
pub fn with_max_length(max_length: usize) -> ValidationConfig
Create a configuration with just character limits
Sourcepub fn with_patterns(patterns: PatternFilters) -> ValidationConfig
pub fn with_patterns(patterns: PatternFilters) -> ValidationConfig
Create a configuration with pattern filters
Sourcepub fn with_mask(mask: DisplayMask) -> ValidationConfig
pub fn with_mask(mask: DisplayMask) -> ValidationConfig
Create a configuration with user-defined display mask
§Examples
use canvas::{ValidationConfig, DisplayMask};
let phone_mask = DisplayMask::new("(###) ###-####", '#');
let config = ValidationConfig::with_mask(phone_mask);Sourcepub fn validate_char_insertion(
&self,
current_text: &str,
position: usize,
character: char,
) -> ValidationResult
pub fn validate_char_insertion( &self, current_text: &str, position: usize, character: char, ) -> ValidationResult
Validate a character insertion at a specific position (raw text space).
Note: Display masks are visual-only and do not participate in validation. Editor logic is responsible for skipping mask separator positions; here we only validate the raw insertion against limits and patterns.
Sourcepub fn validate_content(&self, text: &str) -> ValidationResult
pub fn validate_content(&self, text: &str) -> ValidationResult
Validate the current text content (raw text space)
Sourcepub fn has_validation(&self) -> bool
pub fn has_validation(&self) -> bool
Check if any validation rules are configured
Sourcepub fn has_allowed_values(&self) -> bool
pub fn has_allowed_values(&self) -> bool
Check if whitelist is configured
pub fn allows_field_switch(&self, text: &str) -> bool
Sourcepub fn field_switch_block_reason(&self, text: &str) -> Option<String>
pub fn field_switch_block_reason(&self, text: &str) -> Option<String>
Get reason why field switching is blocked (if any)
Trait Implementations§
Source§impl Clone for ValidationConfig
impl Clone for ValidationConfig
Source§fn clone(&self) -> ValidationConfig
fn clone(&self) -> ValidationConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ValidationConfig
Manual Debug to avoid requiring Debug on dyn CustomFormatter
impl Debug for ValidationConfig
Manual Debug to avoid requiring Debug on dyn CustomFormatter
Source§impl Default for ValidationConfig
impl Default for ValidationConfig
Source§fn default() -> ValidationConfig
fn default() -> ValidationConfig
Auto Trait Implementations§
impl !RefUnwindSafe for ValidationConfig
impl !UnwindSafe for ValidationConfig
impl Freeze for ValidationConfig
impl Send for ValidationConfig
impl Sync for ValidationConfig
impl Unpin for ValidationConfig
impl UnsafeUnpin for ValidationConfig
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more