fluent-rs icon indicating copy to clipboard operation
fluent-rs copied to clipboard

Lazy Value

Open juliancoffee opened this issue 2 years ago • 2 comments

In some cases, one would want to evaluate value only if needed.

I was thinking about using FluentValue::Custom for that, but at the most naive approach using simple closure may not work, because it needs duplicate. To workaround that we could either make our own closure type aka struct of Args and fn and in duplicate, we would duplicate Args and fn. But alternatively, I think it depends on how 'duplicate' is used, because we may also consider just evaluating closure in duplicate and returning a resulting value.

juliancoffee avatar Aug 20 '22 00:08 juliancoffee

In the process of implementing it via FluentValue::Custom and during implementing FluentType for LazyValue, I found that FluentValue doesn't implement FluentType. Shouldn't it? :thinking:

juliancoffee avatar Aug 20 '22 17:08 juliancoffee

I added this documentation to FluentType:

/// Custom types can implement the [`FluentType`] trait in order to generate a string
/// value for use in the message generation process.

So it seems like Custom types are fine being the only implementers.

gregtatum avatar Nov 07 '22 13:11 gregtatum