You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.
In the talk given on Nov. 2 2017 in SF, an audience member asked about "localization". I'm not sure what specific localization techniques were being referred to in the discussion (they were never specified), but I have been using the technique of putting all string resources (for a particular locale) into a (build-time-interchangeable) module.
I merely refer to a constant (const _ &'static str) by name wherever it is needed.
Unfortunately, referring to a const in a Failure display attribute does not appear to be supported:
// in en_us constants modulepubconstMSG_ERR_ARG_VALIDATION:&'static str = "argument validation error";// in error module#[derive(Debug,Fail)]enumErrorKind{#[fail(display = MSG_ERR_ARG_VALIDATION)]
...
While I understand that rich evaluations like method calls in attributes are not supported by Rust today, given how attributes are processed, can this be remedied for constants?
The text was updated successfully, but these errors were encountered:
As things stand today, it looks like manual display implementation is the only option if localization is required (which, in cases such as mine, it is):
use std::fmt;use assayer::ErrorasAssayerError;#[derive(Fail,Debug)]pubenumError{ArgValidation(#[cause]AssayerError),}impl fmt::DisplayforError{fnfmt(&self,f:&mut fmt::Formatter) -> fmt::Result{write!(f, "{}", match *self{Error::ArgValidation(_) => {MSG_ERR_ARG_VALIDATION},
})}}
I'm open to thoughts on how to allow either basic const substitution or possibly even richer expression evaluation in a derive or a macro. Ideas?
In the talk given on Nov. 2 2017 in SF, an audience member asked about "localization". I'm not sure what specific localization techniques were being referred to in the discussion (they were never specified), but I have been using the technique of putting all string resources (for a particular locale) into a (build-time-interchangeable) module.
I merely refer to a constant (
const _ &'static str
) by name wherever it is needed.Unfortunately, referring to a
const
in aFailure
display attribute does not appear to be supported:OK:
Error (error: proc-macro derive panicked):
While I understand that rich evaluations like method calls in attributes are not supported by Rust today, given how attributes are processed, can this be remedied for constants?
The text was updated successfully, but these errors were encountered: