@@ -235,6 +235,9 @@ impl<'source> FluentValue<'source> {
235235 }
236236
237237 /// Converts the [`FluentValue`] to a string.
238+ ///
239+ /// Clones inner values when owned, borrowed data is not cloned.
240+ /// Prefer using [`FluentValue::into_string()`] when possible.
238241 pub fn as_string < R : Borrow < FluentResource > , M > ( & self , scope : & Scope < R , M > ) -> Cow < ' source , str >
239242 where
240243 M : MemoizerKind ,
@@ -253,6 +256,28 @@ impl<'source> FluentValue<'source> {
253256 }
254257 }
255258
259+ /// Converts the [`FluentValue`] to a string.
260+ ///
261+ /// Takes self by-value to be able to skip expensive clones.
262+ /// Prefer this method over [`FluentValue::as_string()`] when possible.
263+ pub fn into_string < R : Borrow < FluentResource > , M > ( self , scope : & Scope < R , M > ) -> Cow < ' source , str >
264+ where
265+ M : MemoizerKind ,
266+ {
267+ if let Some ( formatter) = & scope. bundle . formatter {
268+ if let Some ( val) = formatter ( & self , & scope. bundle . intls ) {
269+ return val. into ( ) ;
270+ }
271+ }
272+ match self {
273+ FluentValue :: String ( s) => s,
274+ FluentValue :: Number ( n) => n. as_string ( ) ,
275+ FluentValue :: Custom ( s) => scope. bundle . intls . stringify_value ( s. as_ref ( ) ) ,
276+ FluentValue :: Error => "" . into ( ) ,
277+ FluentValue :: None => "" . into ( ) ,
278+ }
279+ }
280+
256281 pub fn into_owned < ' a > ( & self ) -> FluentValue < ' a > {
257282 match self {
258283 FluentValue :: String ( str) => FluentValue :: String ( Cow :: from ( str. to_string ( ) ) ) ,
0 commit comments