-
Notifications
You must be signed in to change notification settings - Fork 79
FluentResource entries allocation in FluentBundle is inconsistent #328
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
Comments
I put more thinking into it, and at this point I'm thinking about it similarly to how I think of Intl memoizer (#218) - we could allow for the constructor to pass a ResourceManager instance that the bundle will use to store strings/asts, or, if no manager is passed, the FluentBundle would initialize its own. |
More thinking and prototyping led me eventually in the opposite direction. Instead of trying to allocate a custom In result instead of:
we would write:
I know the change is disruptive, but I believe it's worth considering it to establish a clean API that can be implemented by both JS and Rust alike. |
I think it's worth removing add_messages if it removes a bunch of complexity from FluentBundle at the cost of an extra simple method call by the caller.
Is the idea there that What if add_resource took a |
That's the design we settled on when prototyping with @Manishearth. I know it's not super-pretty, but it's also not intended to be used like that outside of tests and examples. In the real app, you'll have some @Manishearth - what's your take on |
I think it's fine, but it does lead to extra allocation and refcounting overhead which is annoying. Carefully documenting the usage with a resource manager sounds good. Alternatively: allow it to have both add_resource and add_resource_owned, with the latter taking a |
Leaving it alone for now and waiting on real world usage sounds good then. I don't want to push hard for a change based just on a tiny doc example. |
@zbraniecki, did you file this issue in
I'm all for removing |
I filed it here to evaluate removing the method from JS/Python. I'm not sure how tightly we should keep the |
#404 removed the |
While working on fluent-rs I realized that we currently have a rather undefined around memory allocation in FluentBundle.
add_resource
method is intended to take a reference to aFluentResource
stored in someResourceManager
(like L10nRegistry), and in result the signature of the FluentBundle might look like this:Unfortunately, at the same time, we have
add_messages
which accepts a&str
and creates aFluentResource
out of it and then stores its reference.The issue here is that we don't have a place where to allocate and retain the
FluentResource
itself in that scenario.In JS/python this is messy, but hidden. Rust exposes that inconsistency.
In my current model I'm going for sth like that:
so that the resources and their strings are stored on ResourceManager and if two bundles use the same
FluentResource
they both will get immutable reference to it.What should we do about
add_messages
? Is that still useful? If so, would it make sense to require some manager to be available to the bundle such as:or maybe we could consider dropping that and requiring an external resource manager to be used and provide references to the resources?
@stasm - thoughts?
The text was updated successfully, but these errors were encountered: