Enum fluent_syntax::ast::Expression
source · pub enum Expression<S> {
Select {
selector: InlineExpression<S>,
variants: Vec<Variant<S>>,
},
Inline(InlineExpression<S>),
}
Expand description
An expression that is either a select expression or an inline expression.
§Example
use fluent_syntax::parser;
use fluent_syntax::ast;
let ftl = r#"
key = { $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: "key"
},
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,
}),
]
}
);
Variants§
Select
A select expression such as:
key = { $var ->
[key1] Value 1
*[other] Value 2
}
Inline(InlineExpression<S>)
An inline expression such as ${ username }
:
hello-user = Hello ${ username }
Trait Implementations§
source§impl<S: Clone> Clone for Expression<S>
impl<S: Clone> Clone for Expression<S>
source§fn clone(&self) -> Expression<S>
fn clone(&self) -> Expression<S>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<S: Debug> Debug for Expression<S>
impl<S: Debug> Debug for Expression<S>
source§impl<S: PartialEq> PartialEq for Expression<S>
impl<S: PartialEq> PartialEq for Expression<S>
source§fn eq(&self, other: &Expression<S>) -> bool
fn eq(&self, other: &Expression<S>) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.impl<S> StructuralPartialEq for Expression<S>
Auto Trait Implementations§
impl<S> Freeze for Expression<S>where
S: Freeze,
impl<S> RefUnwindSafe for Expression<S>where
S: RefUnwindSafe,
impl<S> Send for Expression<S>where
S: Send,
impl<S> Sync for Expression<S>where
S: Sync,
impl<S> Unpin for Expression<S>where
S: Unpin,
impl<S> UnwindSafe for Expression<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