The current management of FluentResource
and FluentBundle
is likely optimally fast and memory safe, but hard to deal with in reality.
While working on an experiment to bring FluentBundle
and FluentResource
to Gecko via WebIDL, I once again ended up with an expectation to use Rc
.
Sooo, how about if we switch to Rc
? Suddenly, we don't need a fancy resource manager to store FluentResource
objects, and we can freely feed resources to bundle. And if we need two bundles to use the same resource, we just feed them to Rc
s!
Question 1: Is Rc
limiting us in anything major? Since we're targeting fluent-rs
to be a general use crate for localization, is there any common use case which would make fluent-rs
unusable if we switched to Rc
?
The challenge I encountered is that I'm not sure how can I hash references to particular ast::Message
for quick retrieval in the Rc
scenario.
In the current code I have (simplified):
struct FluentBundle<'bundle> {
messages: HashMap<String, &'bundle ast::Message>,
}
impl FluentBundle {
fn add_resource(&mut self, res: &FluentResource) {
for msg in res.body {
self.messages.insert(msg.id.name.to_string(), msg);
}
}
}
now, in the Rc
version I'd have sth like:
struct FluentBundle {
resources: Vec<Rc<FluentResource>>,
messages: HashMap<String, &'? ast::Message>,
}
impl FluentBundle {
fn add_resource(&mut self, res: Rc<FluentResource>) {
self.resources.push(res);
?? // how to hash references to ast::Message ?
}
}
@Manishearth - can you advise on those two issues?