Skip to main content

mf2/
message.rs

1//! One trait over the call-site descriptions, for code that formats any of
2//! them outside Leptos (a native application, a terminal UI adapter).
3
4use crate::{Tr, TrArgs, TrDyn, TrRich};
5use mf2_runtime::{ErrorSink, Formatter, PartSink, Sink};
6
7/// A call-site description `tr!` builds: formatted to text, or to parts.
8pub trait Message {
9    /// Formats it into `out`, reporting errors to `errs`.
10    fn write(&self, f: &Formatter<'_>, out: &mut dyn Sink, errs: &mut dyn ErrorSink);
11
12    /// Formats it to parts — its markup among them — into `out`.
13    fn parts(&self, f: &Formatter<'_>, out: &mut dyn PartSink, errs: &mut dyn ErrorSink);
14}
15
16impl Message for Tr {
17    fn write(&self, f: &Formatter<'_>, out: &mut dyn Sink, errs: &mut dyn ErrorSink) {
18        Tr::write(*self, f, out, errs);
19    }
20
21    fn parts(&self, f: &Formatter<'_>, out: &mut dyn PartSink, errs: &mut dyn ErrorSink) {
22        Tr::parts(*self, f, out, errs);
23    }
24}
25
26impl Message for TrArgs {
27    fn write(&self, f: &Formatter<'_>, out: &mut dyn Sink, errs: &mut dyn ErrorSink) {
28        TrArgs::write(self, f, out, errs);
29    }
30
31    fn parts(&self, f: &Formatter<'_>, out: &mut dyn PartSink, errs: &mut dyn ErrorSink) {
32        TrArgs::parts(self, f, out, errs);
33    }
34}
35
36impl Message for TrRich {
37    fn write(&self, f: &Formatter<'_>, out: &mut dyn Sink, errs: &mut dyn ErrorSink) {
38        TrRich::write(self, f, out, errs);
39    }
40
41    fn parts(&self, f: &Formatter<'_>, out: &mut dyn PartSink, errs: &mut dyn ErrorSink) {
42        TrRich::parts(self, f, out, errs);
43    }
44}
45
46impl Message for TrDyn {
47    fn write(&self, f: &Formatter<'_>, out: &mut dyn Sink, errs: &mut dyn ErrorSink) {
48        TrDyn::write(self, f, out, errs);
49    }
50
51    fn parts(&self, f: &Formatter<'_>, out: &mut dyn PartSink, errs: &mut dyn ErrorSink) {
52        TrDyn::parts(self, f, out, errs);
53    }
54}