Hi all!
I'm one of the authors of the Fluent Localization System and I lead the effort to port it to Rust.
It's still pretty early and so far we're working on the low-level portion of the API, which we hope to eventually wrap in friendly macros.
I'd like to get your opinion on what type of API would you prefer/expect when requesting a localizable value out of a localization "bundle".
The value may be there or not, and if it's there, it may be formatted with or without errors.
Our design principles guide us to always try to return some value, even if we encounter errors.
It means that if you're trying to format a message that references a variable, and we couldn't find or format the variable, we'd like to return partially formatted message because we believe it to be a better user experience over breaking the app.
So, if you have a message like this: hello-user = Hello, { $userName }
and we couldn't resolve $userName
, we'd like to return Hello $userName
and a list of errors we encountered.
To achieve it we see two possible API paths:
Path1
fn format(id: &str) -> Option<Result<String, (String, Vec<Error>)>>{};
Path 2
fn format(id: &str) -> Option<(String, Vec<Error>)>{};
Path1 seems to be more explicit, but also a bit more hassle since you'll have to handle the error scenario coalescing it to the Ok()
scenario and collect errors.
Path2 seems less Rusty, but has the benefit of "You know .0
will be the thing to display, and .1
may have errors".
Any advice on what's a better path to take in Rust?