Skip to content

FluentResource entries allocation in FluentBundle is inconsistent #328

Closed
@zbraniecki

Description

@zbraniecki

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 a FluentResource stored in some ResourceManager (like L10nRegistry), and in result the signature of the FluentBundle might look like this:

struct FluentBundle<'bundle> {
  resources: Vec<&'bundle FluentResource<'bundle>>
}

Unfortunately, at the same time, we have add_messages which accepts a &str and creates a FluentResource 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:

struct ResourceManager {
  strings: HashMap<String, String>,
  resources: HashMap<String, FluentResource>
}

struct FluentBundle<'bundle> {
  resources: Vec<&'bundle FluentResource<'bundle>>
}

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:

let bundle = FluentBundle::new(resmgr);
bundle.add_messages("key = Value");

or maybe we could consider dropping that and requiring an external resource manager to be used and provide references to the resources?

@stasm - thoughts?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions