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
use syn::parse::{Parse, ParseStream};
use syn::spanned::Spanned;
use syn::{braced, Ident, Result, Token};
use crate::widgets::{parse_util, Properties, ReturnedWidget};
impl Parse for ReturnedWidget {
fn parse(input: ParseStream<'_>) -> Result<Self> {
let mut is_optional = false;
let (name, ty) = if input.peek(Ident) {
let name = input.parse()?;
let _colon: Token![:] = input.parse()?;
let ty = input.parse()?;
if input.peek(Token![?]) {
let _mark: Token![?] = input.parse()?;
is_optional = true;
}
(Some(name), Some(ty))
} else {
if input.peek(Token![?]) {
let _mark: Token![?] = input.parse()?;
is_optional = true;
}
(None, None)
};
let name = name.unwrap_or_else(|| {
parse_util::idents_to_snake_case(
[Ident::new("_returned_widget", input.span())].iter(),
ty.span(),
)
});
let inner;
let _token = braced!(inner in input);
let properties = Properties::parse(&inner);
Ok(ReturnedWidget {
name,
ty,
properties,
is_optional,
})
}
}