You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pardon me if this is a Rust newbie question (I am one), but I'm struggling to implement this library in my app.
Very roughly I want to do some negotiation up front and decide on a language fallback stack, then retain that in an immutable struct for the lifetime of the app (a CLI tool). I don't have any problem with this config struct otherwise, it's working and I can even put some language information in it. For example I can use this libraries accepted_languages::parse() and get an owned result back (Vec<LanguageIdentifier>) which I can easily keep in my struct. The issue I have is there seems to be no way to use negotiate_languages() and get back something owned by the calling function. It always returns Vec<&LanguageIdentifier> (which I can't retain in my struct).
Shouldn't there be a built in method that returns something that can be owned by the parent scope?
The text was updated successfully, but these errors were encountered:
After nearly a day of monkeying with it right after asking this I've finally managed to hack my way around this problem by rebuilding everything in the returned vector with clones:
let negotiated = negotiate_languages(&requested,&available,Some(&default),NegotiationStrategy::Filtering,).iter().map(|x| *x).cloned().collect();
I can now stuff that into my struct and return it:
Locales{
negotiated
}
That .iter().map(|x| *x).cloned().collect() business seems like it should be unnecessary, but the negotiate_languages() function does not allow passing ownership of any of the inputs, nor does it generate copies on the output. There is probably an idiomatic Rust way of handling this that I'm missing, but the docs are sparse and it seems to kind of railroad a specific usage.
Pardon me if this is a Rust newbie question (I am one), but I'm struggling to implement this library in my app.
Very roughly I want to do some negotiation up front and decide on a language fallback stack, then retain that in an immutable struct for the lifetime of the app (a CLI tool). I don't have any problem with this config struct otherwise, it's working and I can even put some language information in it. For example I can use this libraries
accepted_languages::parse()
and get an owned result back (Vec<LanguageIdentifier>
) which I can easily keep in my struct. The issue I have is there seems to be no way to usenegotiate_languages()
and get back something owned by the calling function. It always returnsVec<&LanguageIdentifier>
(which I can't retain in my struct).Shouldn't there be a built in method that returns something that can be owned by the parent scope?
The text was updated successfully, but these errors were encountered: