Skip to content

Use of &str in FluentArgs #171

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

Closed
JohnnyJayJay opened this issue Apr 10, 2020 · 1 comment
Closed

Use of &str in FluentArgs #171

JohnnyJayJay opened this issue Apr 10, 2020 · 1 comment

Comments

@JohnnyJayJay
Copy link

As mentioned in #170 , I am currently writing Java bindings for this project.

There is another issue I encountered: the use of &str as a key type in FluentArgs makes insertion of strings from other scopes impossible without leaking memory.
For example, this is not possible, because param is dropped:

fn put(args: &mut FluentArgs, param: String, value: FluentValue) {
    args.insert(&param, value);
}

This results in the fact that you can essentially only use literals as arguments for that method, unless you leak memory to make a &'static str.

My suggestion would be to use a different key type, such as Cow<str> or String. This would certainly be quite a breaking change, so I'm open to ideas how to fix this on the spot.

This issue may not only be relevant for my specific use case, I think.

@JohnnyJayJay
Copy link
Author

I was just made aware of #123 and its corresponding PR. While that doesn't fix it for me, the discussion there gave me the idea to reduce the lifetime of FluentArgs only to the scope where they are needed. It still requires me to go through a fair amount of boiler plate to obtain a HashMap<&str, FluentValue>, but it works now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant