1+ //! Manual version of the minimal test case to isolate the E0223 error
2+ //! This implements what the macro should generate
3+
4+ use super :: * ;
5+
6+ #[ derive( Default , Debug , PartialEq ) ]
7+ pub struct MinimalStructManual {
8+ vec_1 : Vec < String > ,
9+ }
10+
11+ // Manual implementation of what the Former macro should generate
12+ pub struct MinimalStructManualFormerStorage {
13+ pub vec_1 : Option < Vec < String > > ,
14+ }
15+
16+ impl Default for MinimalStructManualFormerStorage {
17+ fn default ( ) -> Self {
18+ Self { vec_1 : None }
19+ }
20+ }
21+
22+ impl former:: Storage for MinimalStructManualFormerStorage {
23+ type Preformed = MinimalStructManual ;
24+ }
25+
26+ impl former:: StoragePreform for MinimalStructManualFormerStorage {
27+ fn preform ( mut self ) -> Self :: Preformed {
28+ let vec_1 = if self . vec_1 . is_some ( ) {
29+ self . vec_1 . take ( ) . unwrap ( )
30+ } else {
31+ Vec :: new ( ) // Default value
32+ } ;
33+ MinimalStructManual { vec_1 }
34+ }
35+ }
36+
37+ #[ derive( Debug ) ]
38+ pub struct MinimalStructManualFormerDefinitionTypes < __Context = ( ) , __Formed = MinimalStructManual > {
39+ _phantom : core:: marker:: PhantomData < ( * const __Context , * const __Formed ) > ,
40+ }
41+
42+ impl < __Context , __Formed > Default for MinimalStructManualFormerDefinitionTypes < __Context , __Formed > {
43+ fn default ( ) -> Self {
44+ Self { _phantom : core:: marker:: PhantomData }
45+ }
46+ }
47+
48+ impl < __Context , __Formed > former:: FormerDefinitionTypes for MinimalStructManualFormerDefinitionTypes < __Context , __Formed > {
49+ type Storage = MinimalStructManualFormerStorage ;
50+ type Formed = __Formed ;
51+ type Context = __Context ;
52+ }
53+
54+ #[ derive( Debug ) ]
55+ pub struct MinimalStructManualFormerDefinition <
56+ __Context = ( ) ,
57+ __Formed = MinimalStructManual ,
58+ __End = former:: ReturnPreformed ,
59+ > {
60+ _phantom : core:: marker:: PhantomData < ( * const __Context , * const __Formed , * const __End ) > ,
61+ }
62+
63+ impl < __Context , __Formed , __End > Default for MinimalStructManualFormerDefinition < __Context , __Formed , __End > {
64+ fn default ( ) -> Self {
65+ Self { _phantom : core:: marker:: PhantomData }
66+ }
67+ }
68+
69+ impl < __Context , __Formed , __End > former:: FormerDefinition for MinimalStructManualFormerDefinition < __Context , __Formed , __End >
70+ where
71+ __End : former:: FormingEnd < MinimalStructManualFormerDefinitionTypes < __Context , __Formed > >
72+ {
73+ type Types = MinimalStructManualFormerDefinitionTypes < __Context , __Formed > ;
74+ type End = __End ;
75+ type Storage = MinimalStructManualFormerStorage ;
76+ type Formed = __Formed ;
77+ type Context = __Context ;
78+ }
79+
80+ pub struct MinimalStructManualFormer < Definition = MinimalStructManualFormerDefinition < ( ) , MinimalStructManual , former:: ReturnPreformed > >
81+ where
82+ Definition : former:: FormerDefinition < Storage = MinimalStructManualFormerStorage > ,
83+ Definition :: Types : former:: FormerDefinitionTypes < Storage = MinimalStructManualFormerStorage >
84+ {
85+ pub storage : Definition :: Storage ,
86+ pub context : Option < Definition :: Context > ,
87+ pub on_end : Option < Definition :: End > ,
88+ }
89+
90+ impl < Definition > MinimalStructManualFormer < Definition >
91+ where
92+ Definition : former:: FormerDefinition < Storage = MinimalStructManualFormerStorage > ,
93+ Definition :: Types : former:: FormerDefinitionTypes < Storage = MinimalStructManualFormerStorage >
94+ {
95+ pub fn new ( on_end : Definition :: End ) -> Self {
96+ Self {
97+ storage : Default :: default ( ) ,
98+ context : None ,
99+ on_end : Some ( on_end) ,
100+ }
101+ }
102+
103+ pub fn form ( mut self ) -> <Definition :: Types as former:: FormerDefinitionTypes >:: Formed {
104+ let on_end = self . on_end . take ( ) . unwrap ( ) ;
105+ let mut context = self . context . take ( ) ;
106+ <Definition :: Types as former:: FormerMutator >:: form_mutation ( & mut self . storage , & mut context) ;
107+ former:: FormingEnd :: < Definition :: Types > :: call ( & on_end, self . storage , context)
108+ }
109+
110+ // Collection setter for vec_1 field
111+ pub fn vec_1 ( self ) -> former:: CollectionFormer <
112+ <Vec < String > as former:: Collection >:: Entry ,
113+ former:: VectorDefinition < String , Self , Self , MinimalStructManualSubformCollectionVec1End < Definition > > ,
114+ >
115+ where
116+ former:: VectorDefinition < String , Self , Self , MinimalStructManualSubformCollectionVec1End < Definition > > :
117+ former:: FormerDefinition <
118+ Storage = Vec < String > ,
119+ Context = Self ,
120+ End = MinimalStructManualSubformCollectionVec1End < Definition > ,
121+ >
122+ {
123+ self . _vec_1_subform_collection :: < former:: CollectionFormer < _ , _ > > ( )
124+ }
125+
126+ pub fn _vec_1_subform_collection < ' a , Former2 > ( self ) -> Former2
127+ where
128+ Former2 : former:: FormerBegin <
129+ ' a ,
130+ former:: VectorDefinition < String , Self , Self , MinimalStructManualSubformCollectionVec1End < Definition > > ,
131+ > ,
132+ former:: VectorDefinition < String , Self , Self , MinimalStructManualSubformCollectionVec1End < Definition > > :
133+ former:: FormerDefinition <
134+ Storage = Vec < String > ,
135+ Context = Self ,
136+ End = MinimalStructManualSubformCollectionVec1End < Definition > ,
137+ > ,
138+ <former:: VectorDefinition < String , Self , Self , MinimalStructManualSubformCollectionVec1End < Definition > > as former:: FormerDefinition >:: Storage : ' a ,
139+ <former:: VectorDefinition < String , Self , Self , MinimalStructManualSubformCollectionVec1End < Definition > > as former:: FormerDefinition >:: Context : ' a ,
140+ <former:: VectorDefinition < String , Self , Self , MinimalStructManualSubformCollectionVec1End < Definition > > as former:: FormerDefinition >:: End : ' a ,
141+ Definition : ' a ,
142+ {
143+ Former2 :: former_begin (
144+ None ,
145+ Some ( self ) ,
146+ MinimalStructManualSubformCollectionVec1End :: < Definition > :: default ( ) ,
147+ )
148+ }
149+ }
150+
151+ // End callback for vec_1 subform collection
152+ pub struct MinimalStructManualSubformCollectionVec1End < Definition > {
153+ _phantom : core:: marker:: PhantomData < ( Definition , ) > ,
154+ }
155+
156+ impl < Definition > Default for MinimalStructManualSubformCollectionVec1End < Definition > {
157+ fn default ( ) -> Self {
158+ Self { _phantom : core:: marker:: PhantomData }
159+ }
160+ }
161+
162+ impl < Definition > former:: FormingEnd < former:: VectorDefinitionTypes < String , MinimalStructManualFormer < Definition > , MinimalStructManualFormer < Definition > > >
163+ for MinimalStructManualSubformCollectionVec1End < Definition >
164+ where
165+ Definition : former:: FormerDefinition < Storage = MinimalStructManualFormerStorage > ,
166+ Definition :: Types : former:: FormerDefinitionTypes < Storage = MinimalStructManualFormerStorage >
167+ {
168+ fn call (
169+ & self ,
170+ storage : Vec < String > ,
171+ super_former : Option < MinimalStructManualFormer < Definition > > ,
172+ ) -> MinimalStructManualFormer < Definition > {
173+ let mut super_former = super_former. unwrap ( ) ;
174+ if let Some ( ref mut field) = super_former. storage . vec_1 {
175+ former:: CollectionAssign :: assign ( field, storage) ;
176+ } else {
177+ super_former. storage . vec_1 = Some ( storage) ;
178+ }
179+ super_former
180+ }
181+ }
182+
183+ impl < __Context , __Formed > former:: FormerMutator for MinimalStructManualFormerDefinitionTypes < __Context , __Formed > { }
184+
185+ impl MinimalStructManual {
186+ pub fn former ( ) -> MinimalStructManualFormer < MinimalStructManualFormerDefinition < ( ) , MinimalStructManual , former:: ReturnPreformed > > {
187+ MinimalStructManualFormer :: new ( former:: ReturnPreformed )
188+ }
189+ }
190+
191+ #[ test]
192+ fn manual_test ( ) {
193+ let _instance = MinimalStructManual :: former ( )
194+ . vec_1 ( )
195+ . add ( "test" . to_string ( ) )
196+ . end ( )
197+ . form ( ) ;
198+ }
0 commit comments