cargo clippy ran

This commit is contained in:
Priec
2025-08-18 19:42:31 +02:00
parent 7b2f021509
commit c915b3287b
25 changed files with 224 additions and 993 deletions

View File

@@ -108,7 +108,7 @@ impl FormattingResult {
pub fn success(formatted: impl Into<String>) -> Self {
FormattingResult::Success {
formatted: formatted.into(),
mapper: Arc::new(DefaultPositionMapper::default()),
mapper: Arc::new(DefaultPositionMapper),
}
}
@@ -117,7 +117,7 @@ impl FormattingResult {
FormattingResult::Warning {
formatted: formatted.into(),
message: message.into(),
mapper: Arc::new(DefaultPositionMapper::default()),
mapper: Arc::new(DefaultPositionMapper),
}
}
@@ -187,7 +187,7 @@ mod tests {
#[test]
fn default_mapper_roundtrip_basic() {
let mapper = DefaultPositionMapper::default();
let mapper = DefaultPositionMapper;
let raw = "01001";
let formatted = "010 01";

View File

@@ -23,8 +23,10 @@ pub struct CharacterLimits {
/// How to count characters for limit checking
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[derive(Default)]
pub enum CountMode {
/// Count actual characters (default)
#[default]
Characters,
/// Count display width (useful for CJK characters)
@@ -34,11 +36,6 @@ pub enum CountMode {
Bytes,
}
impl Default for CountMode {
fn default() -> Self {
CountMode::Characters
}
}
/// Result of a character limit check
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -157,9 +154,7 @@ impl CharacterLimits {
if let Some(max) = self.max_length {
if new_count > max {
return Some(ValidationResult::error(format!(
"Character limit exceeded: {}/{}",
new_count,
max
"Character limit exceeded: {new_count}/{max}"
)));
}
@@ -167,9 +162,7 @@ impl CharacterLimits {
if let Some(warning_threshold) = self.warning_threshold {
if new_count >= warning_threshold && current_count < warning_threshold {
return Some(ValidationResult::warning(format!(
"Approaching character limit: {}/{}",
new_count,
max
"Approaching character limit: {new_count}/{max}"
)));
}
}
@@ -186,9 +179,7 @@ impl CharacterLimits {
if let Some(min) = self.min_length {
if count < min {
return Some(ValidationResult::warning(format!(
"Minimum length not met: {}/{}",
count,
min
"Minimum length not met: {count}/{min}"
)));
}
}
@@ -197,9 +188,7 @@ impl CharacterLimits {
if let Some(max) = self.max_length {
if count > max {
return Some(ValidationResult::error(format!(
"Character limit exceeded: {}/{}",
count,
max
"Character limit exceeded: {count}/{max}"
)));
}
@@ -207,9 +196,7 @@ impl CharacterLimits {
if let Some(warning_threshold) = self.warning_threshold {
if count >= warning_threshold {
return Some(ValidationResult::warning(format!(
"Approaching character limit: {}/{}",
count,
max
"Approaching character limit: {count}/{max}"
)));
}
}
@@ -251,20 +238,16 @@ impl CharacterLimits {
match self.check_limits(text) {
LimitCheckResult::Ok => {
// Show current/max if we have a max limit
if let Some(max) = self.max_length {
Some(format!("{}/{}", self.count(text), max))
} else {
None
}
self.max_length.map(|max| format!("{}/{}", self.count(text), max))
},
LimitCheckResult::Warning { current, max } => {
Some(format!("{}/{} (approaching limit)", current, max))
Some(format!("{current}/{max} (approaching limit)"))
},
LimitCheckResult::Exceeded { current, max } => {
Some(format!("{}/{} (exceeded)", current, max))
Some(format!("{current}/{max} (exceeded)"))
},
LimitCheckResult::TooShort { current, min } => {
Some(format!("{}/{} minimum", current, min))
Some(format!("{current}/{min} minimum"))
},
}
}
@@ -284,8 +267,7 @@ impl CharacterLimits {
let count = self.count(text);
if count > 0 && count < min {
return Some(format!(
"Field must be empty or have at least {} characters (currently: {})",
min, count
"Field must be empty or have at least {min} characters (currently: {count})"
));
}
}

View File

@@ -2,9 +2,11 @@
//! Pure display mask system - user-defined patterns only
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Default)]
pub enum MaskDisplayMode {
/// Only show separators as user types
/// Example: "" → "", "123" → "123", "12345" → "(123) 45"
#[default]
Dynamic,
/// Show full template with placeholders from start
@@ -15,11 +17,6 @@ pub enum MaskDisplayMode {
},
}
impl Default for MaskDisplayMode {
fn default() -> Self {
MaskDisplayMode::Dynamic
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DisplayMask {

View File

@@ -49,8 +49,8 @@ impl std::fmt::Debug for CharacterFilter {
CharacterFilter::Alphabetic => write!(f, "Alphabetic"),
CharacterFilter::Numeric => write!(f, "Numeric"),
CharacterFilter::Alphanumeric => write!(f, "Alphanumeric"),
CharacterFilter::Exact(ch) => write!(f, "Exact('{}')", ch),
CharacterFilter::OneOf(chars) => write!(f, "OneOf({:?})", chars),
CharacterFilter::Exact(ch) => write!(f, "Exact('{ch}')"),
CharacterFilter::OneOf(chars) => write!(f, "OneOf({chars:?})"),
CharacterFilter::Custom(_) => write!(f, "Custom(<function>)"),
}
}
@@ -130,10 +130,10 @@ impl CharacterFilter {
CharacterFilter::Alphabetic => "alphabetic characters (a-z, A-Z)".to_string(),
CharacterFilter::Numeric => "numeric characters (0-9)".to_string(),
CharacterFilter::Alphanumeric => "alphanumeric characters (a-z, A-Z, 0-9)".to_string(),
CharacterFilter::Exact(ch) => format!("exactly '{}'", ch),
CharacterFilter::Exact(ch) => format!("exactly '{ch}'"),
CharacterFilter::OneOf(chars) => {
let char_list: String = chars.iter().collect();
format!("one of: {}", char_list)
format!("one of: {char_list}")
},
CharacterFilter::Custom(_) => "custom filter".to_string(),
}
@@ -207,9 +207,7 @@ impl PatternFilters {
/// Validate entire text against all filters
pub fn validate_text(&self, text: &str) -> Result<(), String> {
for (position, character) in text.char_indices() {
if let Err(error) = self.validate_char_at_position(position, character) {
return Err(error);
}
self.validate_char_at_position(position, character)?
}
Ok(())
}