#[repr(transparent)]
pub struct PromotedPropertyModifierGroup { pub modifiers: Vec<PromotedPropertyModifier>, }

Fields§

§modifiers: Vec<PromotedPropertyModifier>

Implementations§

Examples found in repository?
src/parser/internal/parameters.rs (line 107)
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
pub fn constructor_parameter_list(
    state: &mut State,
    class_name: &str,
) -> Result<ConstructorParameterList, ParseError> {
    let comments = state.stream.comments();

    let left_parenthesis = utils::skip_left_parenthesis(state)?;
    let parameters = utils::comma_separated::<ConstructorParameter>(
        state,
        &|state| {
            attributes::gather_attributes(state)?;

            let modifiers = modifiers::promoted_property_group(modifiers::collect(state)?)?;

            let ty = data_type::optional_data_type(state)?;

            let mut current = state.stream.current();
            let ampersand = if matches!(current.kind, TokenKind::Ampersand) {
                state.stream.next();

                current = state.stream.current();

                Some(current.span)
            } else {
                None
            };

            let ellipsis = if matches!(current.kind, TokenKind::Ellipsis) {
                state.stream.next();
                if !modifiers.is_empty() {
                    return Err(ParseError::VariadicPromotedProperty(current.span));
                }

                Some(current.span)
            } else {
                None
            };

            // 2. Then expect a variable.
            let var = variables::simple_variable(state)?;

            if !modifiers.is_empty() {
                match &ty {
                    Some(ty) => {
                        if ty.includes_callable() || ty.is_bottom() {
                            return Err(ParseError::ForbiddenTypeUsedInProperty(
                                state.named(class_name),
                                var.to_string(),
                                ty.clone(),
                                state.stream.current().span,
                            ));
                        }
                    }
                    None => {
                        if modifiers.has_readonly() {
                            return Err(ParseError::MissingTypeForReadonlyProperty(
                                state.named(class_name),
                                var.to_string(),
                                state.stream.current().span,
                            ));
                        }
                    }
                }
            }

            let mut default = None;
            if state.stream.current().kind == TokenKind::Equals {
                state.stream.next();
                default = Some(expressions::create(state)?);
            }

            Ok(ConstructorParameter {
                comments: state.stream.comments(),
                name: var,
                attributes: state.get_attributes(),
                data_type: ty,
                ellipsis,
                default,
                modifiers,
                ampersand,
            })
        },
        TokenKind::RightParen,
    )?;

    let right_parenthesis = utils::skip_right_parenthesis(state)?;

    Ok(ConstructorParameterList {
        comments,
        left_parenthesis,
        parameters,
        right_parenthesis,
    })
}
Examples found in repository?
src/parser/internal/parameters.rs (line 132)
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
pub fn constructor_parameter_list(
    state: &mut State,
    class_name: &str,
) -> Result<ConstructorParameterList, ParseError> {
    let comments = state.stream.comments();

    let left_parenthesis = utils::skip_left_parenthesis(state)?;
    let parameters = utils::comma_separated::<ConstructorParameter>(
        state,
        &|state| {
            attributes::gather_attributes(state)?;

            let modifiers = modifiers::promoted_property_group(modifiers::collect(state)?)?;

            let ty = data_type::optional_data_type(state)?;

            let mut current = state.stream.current();
            let ampersand = if matches!(current.kind, TokenKind::Ampersand) {
                state.stream.next();

                current = state.stream.current();

                Some(current.span)
            } else {
                None
            };

            let ellipsis = if matches!(current.kind, TokenKind::Ellipsis) {
                state.stream.next();
                if !modifiers.is_empty() {
                    return Err(ParseError::VariadicPromotedProperty(current.span));
                }

                Some(current.span)
            } else {
                None
            };

            // 2. Then expect a variable.
            let var = variables::simple_variable(state)?;

            if !modifiers.is_empty() {
                match &ty {
                    Some(ty) => {
                        if ty.includes_callable() || ty.is_bottom() {
                            return Err(ParseError::ForbiddenTypeUsedInProperty(
                                state.named(class_name),
                                var.to_string(),
                                ty.clone(),
                                state.stream.current().span,
                            ));
                        }
                    }
                    None => {
                        if modifiers.has_readonly() {
                            return Err(ParseError::MissingTypeForReadonlyProperty(
                                state.named(class_name),
                                var.to_string(),
                                state.stream.current().span,
                            ));
                        }
                    }
                }
            }

            let mut default = None;
            if state.stream.current().kind == TokenKind::Equals {
                state.stream.next();
                default = Some(expressions::create(state)?);
            }

            Ok(ConstructorParameter {
                comments: state.stream.comments(),
                name: var,
                attributes: state.get_attributes(),
                data_type: ty,
                ellipsis,
                default,
                modifiers,
                ampersand,
            })
        },
        TokenKind::RightParen,
    )?;

    let right_parenthesis = utils::skip_right_parenthesis(state)?;

    Ok(ConstructorParameterList {
        comments,
        left_parenthesis,
        parameters,
        right_parenthesis,
    })
}

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
Deserialize this value from the given Serde deserializer. Read more
The name of the generated JSON Schema. Read more
Generates a JSON Schema for this type. Read more
Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Serialize this value into the given Serde serializer. Read more

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
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.