rustidy_ast/expr/without_block/
struct_.rs1use {
5 crate::{attr::{self, WithOuterAttributes}, expr::Expression, token, util::Braced},
6 super::{TupleIndex, path::PathInExpression},
7 rustidy_ast_util::{Identifier, Punctuated, delimited, punct},
8 rustidy_format::{Format, Formattable, WhitespaceConfig, WhitespaceFormat},
9 rustidy_parse::{Parse, ParserTag},
10 rustidy_print::Print,
11 rustidy_util::Whitespace,
12};
13
14#[derive(PartialEq, Eq, Clone, Debug)]
16#[derive(serde::Serialize, serde::Deserialize)]
17#[derive(Parse, Formattable, Format, Print)]
18#[parse(name = "a struct expression")]
19#[parse(skip_if_tag = ParserTag::SkipStructExpression)]
20pub struct StructExpression {
21 pub path: PathInExpression,
22 #[format(prefix_ws = Whitespace::SINGLE)]
23 #[format(args = delimited::fmt_single_or_indent_if_non_blank(
24 50,
25 StructExprFieldsFmt { field_prefix_ws: Whitespace::SINGLE },
26 StructExprFieldsFmt { field_prefix_ws: Whitespace::INDENT }
27 ))]
28 pub inner: Braced<Option<StructExpressionInner>>,
29}
30
31#[derive(PartialEq, Eq, Clone, Debug)]
32#[derive(serde::Serialize, serde::Deserialize)]
33#[derive(Parse, Formattable, Format, Print)]
34#[format(args(ty = "StructExprFieldsFmt"))]
35pub enum StructExpressionInner {
36 #[format(args = args)]
37 Fields(StructExprFields),
38 Base(StructBase),
39}
40
41#[derive(PartialEq, Eq, Clone, Debug)]
43#[derive(serde::Serialize, serde::Deserialize)]
44#[derive(Parse, Formattable, Format, Print)]
45#[format(args(ty = "StructExprFieldsFmt"))]
46pub struct StructExprFields {
47 #[format(args = punct::fmt_with(
48 args.field_prefix_ws,
49 Whitespace::REMOVE,
50 args,
51 ()
52 ))]
53 pub fields: Punctuated<StructExprField, token::Comma>,
54 #[format(prefix_ws = Whitespace::REMOVE)]
55 pub end: Option<StructExprFieldsEnd>,
56}
57
58#[derive(Clone, Copy, Debug)]
59pub struct StructExprFieldsFmt {
60 field_prefix_ws: WhitespaceConfig,
61}
62
63#[derive(PartialEq, Eq, Clone, Debug)]
64#[derive(serde::Serialize, serde::Deserialize)]
65#[derive(Parse, Formattable, Format, Print)]
66pub enum StructExprFieldsEnd {
67 Base(StructExprFieldsEndBase),
68 TrailingComma(token::Comma),
69}
70
71#[derive(PartialEq, Eq, Clone, Debug)]
72#[derive(serde::Serialize, serde::Deserialize)]
73#[derive(Parse, Formattable, Format, Print)]
74pub struct StructExprFieldsEndBase {
75 pub comma: token::Comma,
76 #[format(prefix_ws = Whitespace::SINGLE)]
77 pub base: StructBase,
78}
79
80#[derive(PartialEq, Eq, Clone, Debug)]
82#[derive(serde::Serialize, serde::Deserialize)]
83#[derive(Parse, Formattable, Format, Print)]
84#[format(args(ty = "StructExprFieldsFmt"))]
85pub struct StructExprField(
86 #[format(args = attr::with::fmt(args.field_prefix_ws))]
87 pub WithOuterAttributes<StructExprFieldInner>,
88);
89
90#[derive(PartialEq, Eq, Clone, Debug)]
91#[derive(serde::Serialize, serde::Deserialize)]
92#[derive(Parse, Formattable, Format, Print)]
93pub enum StructExprFieldInner {
94 WithExpr(StructExprFieldInnerWithExpr),
95 Ident(Identifier),
96}
97
98#[derive(PartialEq, Eq, Clone, Debug)]
99#[derive(serde::Serialize, serde::Deserialize)]
100#[derive(Parse, Formattable, Format, Print)]
101pub struct StructExprFieldInnerWithExpr {
102 pub start: StructExprFieldInnerWithExprStart,
103 #[format(prefix_ws = Whitespace::REMOVE)]
104 pub colon: token::Colon,
105 #[format(prefix_ws = Whitespace::SINGLE)]
106 pub expr: Expression,
107}
108
109#[derive(PartialEq, Eq, Clone, Debug)]
110#[derive(serde::Serialize, serde::Deserialize)]
111#[derive(Parse, Formattable, Format, Print)]
112pub enum StructExprFieldInnerWithExprStart {
113 Ident(Identifier),
114 Tuple(TupleIndex),
115}
116
117#[derive(PartialEq, Eq, Clone, Debug)]
119#[derive(serde::Serialize, serde::Deserialize)]
120#[derive(Parse, Formattable, Format, Print)]
121pub struct StructBase {
122 pub dot_dot: token::DotDot,
123 #[format(prefix_ws = Whitespace::REMOVE)]
124 pub expr: Expression,
125}