-
Notifications
You must be signed in to change notification settings - Fork 31
Open
Description
I try to match the following enum with internal struct variants
pub enum ValidationError {
LengthOutOfBounds {
min: usize,
max: usize,
},
InvalidName {
invalid_chars: Vec<char>,
},
UniqueConstraintViolation,
}with
@use crate::ValidationError::{self, *};
@(error: &ValidationError)
@match error {
UniqueConstraintViolation => {
This name is taken.
}
LengthOutOfBounds { min, max } => {
This field must contain at min @min and at max @max characters.
}
InvalidName { invalid_chars } => {
@format!("The name must not contain any of the following characters: {:?}", invalid_chars)
}
}The error message is:
warning: Template parse error in "template_src/validation_error_display_part.rs.html":
warning: 5:@match error {
warning: ^ Error in expression starting here:
warning: 5:@match error {
warning: ^ Error in match expression:
warning: 8: }
warning: ^ Error in match arm starting here:
this works:
@use crate::ValidationError::{self, *};
@(error: &ValidationError)
@match error {
UniqueConstraintViolation(value) => {
This name is taken.
}
_ => {
other error
}
}
In rust this works:
impl<'s> std::fmt::Display for ValidationError<'s> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
use ValidationError::*;
match self {
LengthOutOfBounds { min, max } => {
write!(
f,
"This field must contain at min {} and at max {} characters.",
min, max
)
}
InvalidName {
invalid_chars,
} => {
write!(
f,
"The name must not contain any of the following characters: {:?}",
invalid_chars
)
}
UniqueConstraintViolation => {
write!(f, "This name is taken.")
}
}
}
}Am I doing something wrong? Is this a defect of the library?
I enjoy using ructe 🦀 thankyou for sharing 🙏
Metadata
Metadata
Assignees
Labels
No labels