Skip to content
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

Make FluentArgs a trait? #319

Open
dhardy opened this issue May 17, 2023 · 1 comment
Open

Make FluentArgs a trait? #319

dhardy opened this issue May 17, 2023 · 1 comment
Labels
crate:fluent-bundle Issues related to fluent-bundle crate enhancement

Comments

@dhardy
Copy link

dhardy commented May 17, 2023

FluentArgs's key API (beyond construction) would appear to be get. Maybe also iter; I don't know if that's actually needed.

Can we replace the type with a trait?

pub trait Arguments {
    fn get(&self, key: &str) -> Option<FluentValue<'_>>;

    // if necessary:
    // type Iter<'a>: Iterator<Item = (&'a str, FluentValue<'a>)> + 'a;
    // fn iter(&self) -> Self::Iter<'_>;
    // (Later this can just use impl Trait: see RFC#3425.)
}

(Technically, FluentArgs and fluent_args! don't need to change, but FluentBundle::write_pattern, format_pattern should use the trait.)

Motivation: this allows any type implementing fluent::Arguments to be used as arguments (often just via a derive macro). So, say, a Druid widget FluentText: druid::Widget<T> with data: &T could directly use that data type as arguments.


Edit: return FluentValue by value not ref to allow construction in get and Iterator::next.

@dhardy
Copy link
Author

dhardy commented May 17, 2023

Catch: in some cases the data might be a simple type, e.g. i32.
Solution: provide implementations of Arguments for such types using a fixed key ("value"?).

@alerque alerque added enhancement crate:fluent-bundle Issues related to fluent-bundle crate labels May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate:fluent-bundle Issues related to fluent-bundle crate enhancement
Projects
None yet
Development

No branches or pull requests

2 participants