Struct fluent_syntax::ast::Variant [−][src]
pub struct Variant<S> {
pub key: VariantKey<S>,
pub value: Pattern<S>,
pub default: bool,
}
Expand description
Variant is a single branch of a value in a Select
expression.
It’s a pair of VariantKey
and Pattern
. If the selector match the
key, then the value of the variant is returned as the value of the expression.
Example
use fluent_syntax::parser;
use fluent_syntax::ast;
let ftl = r#"
hello-world = { $var ->
[key1] Value 1
*[other] Value 2
}
"#;
let resource = parser::parse(ftl)
.expect("Failed to parse an FTL resource.");
assert_eq!(
resource,
ast::Resource {
body: vec![
ast::Entry::Message(ast::Message {
id: ast::Identifier {
name: "hello-world"
},
value: Some(ast::Pattern {
elements: vec![
ast::PatternElement::Placeable {
expression: ast::Expression::Select {
selector: ast::InlineExpression::VariableReference {
id: ast::Identifier { name: "var" },
},
variants: vec![
ast::Variant {
key: ast::VariantKey::Identifier {
name: "key1"
},
value: ast::Pattern {
elements: vec![
ast::PatternElement::TextElement {
value: "Value 1",
}
]
},
default: false,
},
ast::Variant {
key: ast::VariantKey::Identifier {
name: "other"
},
value: ast::Pattern {
elements: vec![
ast::PatternElement::TextElement {
value: "Value 2",
}
]
},
default: true,
},
]
}
}
]
}),
attributes: vec![],
comment: None,
}),
]
}
);
Fields
key: VariantKey<S>
value: Pattern<S>
default: bool
Trait Implementations
Auto Trait Implementations
impl<S> RefUnwindSafe for Variant<S> where
S: RefUnwindSafe,
impl<S> UnwindSafe for Variant<S> where
S: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more