projectfluent / fluent-rs

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

Allow optional arguments #273

Closed MathieuTricoire closed 1 year ago

MathieuTricoire commented 1 year ago

Any thoughts about implementing From for Option?:

impl<T> From<Option<T>> for FluentValue
where
    T: Into<FluentValue>

I find interesting to allow something like this:

busy = { $gender ->
    [male] Occupé
    [female] Occupée
   *[other] Non disponible
}
let gender: Option<String> = None;
let mut args = FluentArgs::new();
args.set("gender", gender.into());
let value = bundle.format_pattern(&pattern, Some(&args), &mut errors);
MathieuTricoire commented 1 year ago

It seems reasonable to me. I'm marking request changes for a simple unit test. Most the existing tests are more on the integration level, but a unit test here should be good enough for merging.

I've added an integration test, I think it fits more with what exists, is that ok?

gregtatum commented 1 year ago

The CI was failing for code coverage, but it's passing in #276, so this looks fine to merge.