I'm the leading engineer behind
fluent-rs - Rust implementation of the Fluent Localization System.
I'm working on final touches on the low level crate that operates on the FTL file format used by Fluent.
The AST is currently using
&str over a source String which makes the AST read-only. The most critical use of the parser/AST is runtime where read-only is totally enough.
But it's tempting to use the same AST/parser for tooling where ability to modify the AST and serialize it after is important.
I see several possible approaches to that, and I'm not sure how to weight pros and cons and if maybe I missed some other option.
Here's the issue about it - https://github.com/projectfluent/fluent-rs/issues/104
I'd appreciate help with making the decision and any feedback from other crates that implemented parser/AST/serializer and had to make similar decisions.
We also have a couple more decisions to make prior to 1.0 release - https://github.com/projectfluent/fluent-rs/labels/fluent-syntax
Appreciate feedback and help!
Cow<'_, str> seems fine to me, although I am not a user of
But here is a neat trick that allows you to have both:
whenever your AST
&'s str, you should be able to use some parametric type
Str, where your struct is generic over
<'s, Str : From<&'s str> + Clone + Deref<Target = str> + 's>.
And then, add mutation functions for a specific monomoprhisation of your AST:
Str = Cow<'a, str> or even
Str = String
I'm not knowledgeable enough about this myself, but if I would look for inspiration, there are two places that come to mind that work with strings, with parsing them zero copy, and for the latter maybe mutate them as well:
- Servo which parses html, using tendril
- xi-editor which uses ropes
Unfortunately the last update on both tendril and xi-rope starts to date a bit, but there are other rope implementations, like ropey which seems pretty active.
Cow seems to be made for the job, unless you have large strings and you only want to store some delta modification, rather than making a copy of the whole string on change.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.