projectfluent / fluent-rs

Rust implementation of Project Fluent
https://projectfluent.org
Apache License 2.0
1.08k stars 97 forks source link

Consider switching format_pattern to (String, Vec<Error>) #125

Closed zbraniecki closed 4 years ago

zbraniecki commented 5 years ago

Are you still planning to change the return value of format_pattern to (String, Option<Vec<Error>>)?

Originally posted by @stasm in https://github.com/projectfluent/fluent-rs/pull/120

stasm commented 5 years ago

Related: we could also consider removing errors from the signature of format_pattern.

zbraniecki commented 5 years ago

Related: we could also consider removing errors from the signature of format_pattern.

What do you mean by that?

stasm commented 5 years ago

Since errors would be returned from format_pattern (wrapped in an Option), I think there's little use left for the third argument to format_pattern. We could thus change:

let value = bundle.format_pattern(&pattern, Some(&args), &mut errors);

to:

let (value, maybe_errors) = bundle.format_pattern(&pattern, Some(&args));
zbraniecki commented 5 years ago

Ah yes, that was my thinking as well!

zbraniecki commented 5 years ago

This gets moved to 0.8.

zbraniecki commented 4 years ago

I actually went the other direction - I now accept a &Vec of Errors that FluentBundle populates. I think this is a better approach as it allows the user to decide how to handle errors (per format, or per list of formats) without any additional allocations.

I may also switch to allow not to pass the errors in which case errors won't be populated at all.

zbraniecki commented 4 years ago

I'm going to close it. I believe that errors vec should not be allocated as part of the return value, and instead should be passed to the call in some higher level code that will handle the outcome of errors (fallbacks, reporting etc.).