-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: FromStr derive could support setting the error type #380
feat: FromStr derive could support setting the error type #380
Conversation
This looks really good! Sorry for the delay reviewing it |
pub fn missing_parse_err_attr_error() -> syn::Error { | ||
syn::Error::new( | ||
Span::call_site(), | ||
"`parse_err_ty` and `parse_err_fn` attribute is both required.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"`parse_err_ty` and `parse_err_fn` attribute is both required.", | |
"`parse_err_ty` and `parse_err_fn` attributes are both required.", |
Please reconsider using string literals for paths. Attributes nowadays support arbitrary expressions (including paths) instead of only string literals. One of the authors of |
@sebschrader So you want like this? #[derive(Debug, EnumString)]
#[strum(
parse_err_fn = crate::custom::some_enum_not_found_err,
parse_err_ty = crate::custom::CaseCustomParseErrorNotFoundError
)]
enum CaseCustomParseErrorEnum {
#[strum(serialize = "red")]
Red,
#[strum(serialize = "blue")]
Blue,
}
mod custom {
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
struct CaseCustomParseErrorNotFoundError(String);
impl std::fmt::Display for CaseCustomParseErrorNotFoundError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "not found `{}`", self.0)
}
}
impl std::error::Error for CaseCustomParseErrorNotFoundError {}
pub fn some_enum_not_found_err(s: &str) -> CaseCustomParseErrorNotFoundError {
CaseCustomParseErrorNotFoundError(s.to_string())
}
} |
resolve #91 #332 #221
PR checker failed because #381