pub struct DisplayMask { /* private fields */ }Implementations§
Source§impl DisplayMask
impl DisplayMask
Sourcepub fn new(pattern: impl Into<String>, input_char: char) -> Self
pub fn new(pattern: impl Into<String>, input_char: char) -> Self
Create a new display mask with dynamic mode (current behavior)
§Arguments
pattern- The mask pattern (e.g., “##-##-####”, “(###) ###-####”)input_char- Character representing input positions (usually ‘#’)
§Examples
use validation_core::DisplayMask;
// Phone number format
let phone_mask = DisplayMask::new("(###) ###-####", '#');
// Date format
let date_mask = DisplayMask::new("##/##/####", '#');
// Custom business format
let employee_id = DisplayMask::new("EMP-####-##", '#');Sourcepub fn with_mode(self, mode: MaskDisplayMode) -> Self
pub fn with_mode(self, mode: MaskDisplayMode) -> Self
Set the display mode for this mask
§Examples
use validation_core::{DisplayMask, MaskDisplayMode};
let dynamic_mask = DisplayMask::new("##-##", '#')
.with_mode(MaskDisplayMode::Dynamic);
let template_mask = DisplayMask::new("##-##", '#')
.with_mode(MaskDisplayMode::Template { placeholder: '_' });Sourcepub fn with_template(self, placeholder: char) -> Self
pub fn with_template(self, placeholder: char) -> Self
Set template mode with custom placeholder
§Examples
use validation_core::DisplayMask;
let phone_template = DisplayMask::new("(###) ###-####", '#')
.with_template('_'); // Shows "(___) ___-____" when empty
let date_dots = DisplayMask::new("##/##/####", '#')
.with_template('•'); // Shows "••/••/••••" when emptySourcepub fn apply_to_display(&self, raw_input: &str) -> String
pub fn apply_to_display(&self, raw_input: &str) -> String
Apply mask to raw input, showing visual separators and handling display mode
Sourcepub fn is_input_position(&self, display_position: usize) -> bool
pub fn is_input_position(&self, display_position: usize) -> bool
Check if a display position should accept cursor/input
Sourcepub fn display_pos_to_raw_pos(&self, display_pos: usize) -> usize
pub fn display_pos_to_raw_pos(&self, display_pos: usize) -> usize
Map display position to raw position
Sourcepub fn raw_pos_to_display_pos(&self, raw_pos: usize) -> usize
pub fn raw_pos_to_display_pos(&self, raw_pos: usize) -> usize
Map raw position to display position
Sourcepub fn next_input_position(&self, display_pos: usize) -> usize
pub fn next_input_position(&self, display_pos: usize) -> usize
Find next input position at or after the given display position
Sourcepub fn prev_input_position(&self, display_pos: usize) -> Option<usize>
pub fn prev_input_position(&self, display_pos: usize) -> Option<usize>
Find previous input position at or before the given display position
Sourcepub fn display_mode(&self) -> &MaskDisplayMode
pub fn display_mode(&self) -> &MaskDisplayMode
Get the display mode
Sourcepub fn is_template_mode(&self) -> bool
pub fn is_template_mode(&self) -> bool
Check if this mask uses template mode
Sourcepub fn input_char(&self) -> char
pub fn input_char(&self) -> char
Get the input placeholder character
Sourcepub fn first_input_position(&self) -> usize
pub fn first_input_position(&self) -> usize
Get the position of the first input character in the pattern
Trait Implementations§
Source§impl Clone for DisplayMask
impl Clone for DisplayMask
Source§fn clone(&self) -> DisplayMask
fn clone(&self) -> DisplayMask
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DisplayMask
impl Debug for DisplayMask
Source§impl Default for DisplayMask
impl Default for DisplayMask
Source§impl<'de> Deserialize<'de> for DisplayMask
impl<'de> Deserialize<'de> for DisplayMask
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for DisplayMask
Source§impl PartialEq for DisplayMask
impl PartialEq for DisplayMask
Source§fn eq(&self, other: &DisplayMask) -> bool
fn eq(&self, other: &DisplayMask) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl Serialize for DisplayMask
impl Serialize for DisplayMask
impl StructuralPartialEq for DisplayMask
Auto Trait Implementations§
impl Freeze for DisplayMask
impl RefUnwindSafe for DisplayMask
impl Send for DisplayMask
impl Sync for DisplayMask
impl Unpin for DisplayMask
impl UnsafeUnpin for DisplayMask
impl UnwindSafe for DisplayMask
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
Mutably borrows from an owned value. Read more