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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.