Struct jql::Group

source ·
pub struct Group {
    pub filters: Vec<Filter>,
    pub root: Option<()>,
    pub selectors: Vec<Selector>,
    pub spread: Option<()>,
    pub truncate: Option<()>,
}
Expand description

A Group is a set of grammar elements used to define a selection.

Fields§

§filters: Vec<Filter>

Filters.

§root: Option<()>

Root marker.

§selectors: Vec<Selector>

Selectors.

§spread: Option<()>

Spread marker.

§truncate: Option<()>

Truncate marker.

Implementations§

Group implementations.

Creates a new group.

Examples found in repository?
src/types.rs (line 106)
105
106
107
    fn default() -> Self {
        Self::new()
    }
More examples
Hide additional examples
src/parser.rs (line 144)
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
pub fn selectors_parser(selectors: &str) -> Result<Vec<Group>, String> {
    match GroupsParser::parse(Rule::groups, selectors) {
        Ok(pairs) => {
            let mut groups: Vec<Group> = Vec::new();

            for pair in pairs {
                let mut group = Group::new();

                // Loop over the pairs converted as an iterator of the tokens
                // which composed it.
                for inner_pair in pair.into_inner() {
                    let inner_span = inner_pair.clone().as_span().as_str();

                    // Populate the group based on the rules found by the
                    // parser.
                    match inner_pair.as_rule() {
                        // Default
                        Rule::default => group
                            .selectors
                            .push(span_to_default(&get_chars_from_pair(inner_pair)[0].clone())),
                        Rule::filter_default => {
                            group.filters.push(Filter::Default(span_to_default(
                                &get_chars_from_pair(inner_pair.into_inner().next().unwrap())[0]
                                    .clone(),
                            )))
                        }

                        // Index
                        Rule::index => group.selectors.push(span_to_index(inner_span)),
                        Rule::filter_index => group
                            .filters
                            .push(Filter::Default(span_to_index(inner_span))),

                        // Range
                        Rule::range => group.selectors.push(span_to_range(inner_pair)),
                        Rule::filter_range => group.filters.push(Filter::Default(span_to_range(
                            inner_pair.into_inner().next().unwrap(),
                        ))),

                        // Property
                        Rule::property => group
                            .selectors
                            .push(Selector::Object(get_inner_object_from_pair(inner_pair))),
                        Rule::filter_property => group.filters.push(Filter::Default(
                            Selector::Object(get_inner_object_from_pair(inner_pair)),
                        )),

                        // Filter lens property.
                        Rule::filter_lens_property => group.filters.push(Filter::Lens(
                            Selector::Object(get_inner_object_from_pair(inner_pair)),
                        )),

                        // Root
                        Rule::root => group.root = Some(()),

                        // Spread
                        Rule::spread => group.spread = Some(()),

                        // Truncate
                        Rule::truncate => group.truncate = Some(()),
                        _ => (),
                    };
                }

                // Add the group.
                groups.push(group);
            }

            Ok(groups)
        }
        Err(_) => Err(String::from("Error, unable to parse invalid selectors")),
    }
}

Trait Implementations§

Formats the value using the given formatter. Read more
Returns the “default value” for a type. 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.

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
Compare self to key and return true if they are equal.

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 alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. 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.