Struct fluent_syntax::ast::Variant
source · 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§
source§impl<S: PartialEq> PartialEq for Variant<S>
impl<S: PartialEq> PartialEq for Variant<S>
impl<S> StructuralPartialEq for Variant<S>
Auto Trait Implementations§
impl<S> Freeze for Variant<S>where
S: Freeze,
impl<S> RefUnwindSafe for Variant<S>where
S: RefUnwindSafe,
impl<S> Send for Variant<S>where
S: Send,
impl<S> Sync for Variant<S>where
S: Sync,
impl<S> Unpin for Variant<S>where
S: Unpin,
impl<S> UnwindSafe for Variant<S>where
S: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more