es_fluent/traits/
fluent_display.rs1use std::fmt;
2
3pub trait FluentDisplay {
6 fn fluent_fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result;
8}
9
10pub trait ToFluentString {
13 fn to_fluent_string(&self) -> String;
15}
16
17impl<T: FluentDisplay + ?Sized> ToFluentString for T {
18 fn to_fluent_string(&self) -> String {
19 struct FluentDisplayWrapper<'a, T: ?Sized> {
20 inner: &'a T,
21 }
22
23 impl<'a, T: FluentDisplay + ?Sized> fmt::Display for FluentDisplayWrapper<'a, T> {
24 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25 self.inner.fluent_fmt(f)
26 }
27 }
28
29 FluentDisplayWrapper { inner: self }.to_string()
30 }
31}