1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use proc_macro2::TokenStream as TokenStream2;
use quote::quote;
use crate::widgets::{
ConditionalBranches, ConditionalWidget, Properties, Property, PropertyType, ReturnedWidget,
SignalHandler, Widget,
};
impl Property {
fn destructure_stream(&self, stream: &mut TokenStream2) {
match &self.ty {
PropertyType::Widget(widget) => widget.destructure_stream(stream),
PropertyType::SignalHandler(signal_handler) => {
signal_handler.destructure_stream(stream);
}
PropertyType::ConditionalWidget(cond_widget) => {
cond_widget.destructure_stream(stream);
}
PropertyType::Assign(_) | PropertyType::ParseError(_) => (),
}
}
}
impl Properties {
fn destructure_stream(&self, stream: &mut TokenStream2) {
for prop in &self.properties {
prop.destructure_stream(stream);
}
}
}
impl Widget {
pub(crate) fn destructure_stream(&self, stream: &mut TokenStream2) {
if self.has_struct_field() {
let name = &self.name;
stream.extend(quote! { #name, });
}
self.properties.destructure_stream(stream);
}
}
impl ConditionalWidget {
fn destructure_stream(&self, stream: &mut TokenStream2) {
let name = &self.name;
stream.extend(quote! { #name, });
match &self.branches {
ConditionalBranches::If(if_branches) => {
for branch in if_branches {
branch.widget.destructure_stream(stream);
}
}
ConditionalBranches::Match((_, _, match_arms)) => {
for arm in match_arms {
arm.widget.destructure_stream(stream);
}
}
}
}
}
impl ReturnedWidget {
pub(super) fn destructure_stream(&self, stream: &mut TokenStream2) {
if self.ty.is_some() {
let name = &self.name;
stream.extend(quote! {
#name,
});
}
self.properties.destructure_stream(stream);
}
}
impl SignalHandler {
pub(super) fn destructure_stream(&self, stream: &mut TokenStream2) {
if let Some(signal_handler_id) = &self.handler_id {
stream.extend(quote! {
#signal_handler_id,
});
}
}
}