Skip to content

Provide Way to Avoid Allocating To Collect Formatting Errors #323

Open
@zicklag

Description

@zicklag

The bundle.format_pattern() method takes a &mut Vec<FluentError> to allow you to respond to errors, but I have a situation where my bundle struct is accessed concurrently across multiple threads with just a read-only reference.

I'm trying to avoid allocating every time I need to format a message. Usually, if I had mutable access, I'd just pre-allocate the vector for collecting the errors, and re-use that vector every time I format a message, but since I've only got concurrent access to my helper function for formatting, that isn't possible.

On thought is that I could pass in an FnMut closure that will be called every time there is an error. This would allow me to choose how I handle the error message without requiring an allocation.

In this case, I simply wish to log the error using the log or tracing crates.


On a related note, I just noticed that FluentArgs also allocates since it contains a Vec. I wonder if we could make that an iterator or something like that. 🤔 If it was a double-ended iterator, then that would allow us to iterate back and forth through it to find the keys in it as needed.

I'm using fluent for game development so avoiding allocations per-frame is really important where possible.

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