message_format/ast/mod.rs
1// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
2// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
3// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
4// option. This file may not be copied, modified, or distributed
5// except according to those terms.
6
7//! Message Format AST
8//!
9
10use std::fmt;
11
12mod plural_classifiers;
13mod plural_format;
14mod select_format;
15mod simple_format;
16
17pub use self::plural_classifiers::*;
18pub use self::plural_format::{PluralCategory, PluralFormat};
19pub use self::select_format::SelectFormat;
20pub use self::simple_format::SimpleFormat;
21
22use super::Args;
23
24/// The part of a message which formats a value.
25pub trait Format {
26 /// Format this message part.
27 fn format_message_part(&self, stream: &mut fmt::Write, args: &Args) -> fmt::Result;
28}
29
30/// Either some plain text (string)
31/// or something to be formatted.
32pub enum MessagePart {
33 /// A message part which is a piece of plain text
34 /// that needs no formatting.
35 String(String),
36 /// Magic value used internally by some formats. Currently
37 /// only used for `PluralFormat`.
38 Placeholder,
39 /// A message part which needs to be formatted.
40 Format(Box<Format>),
41}