former 2.45.0

A flexible implementation of the Builder pattern supporting nested builders and collection-specific subformers. Simplify the construction of complex objects.
Documentation
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
#![allow(clippy::used_underscore_binding, clippy::all, warnings, missing_docs)]
#![allow(dead_code)]

#[ allow( unused_imports ) ]
use super::*;
#[ allow( unused_imports ) ]
use test_tools::a_id;
#[ allow( unused_imports ) ]
use collection_tools::HashMap;

// Child struct with Former derived for builder pattern support
// xxx : Re-enable when trailing comma issue is fully fixed in macro_tools::generic_params::decompose
// #[ derive( Clone, Debug, PartialEq, former::Former ) ]
#[ derive( Clone, Debug, PartialEq ) ]
pub struct Child {
  name: String,
  description: String,
}

// Parent struct to hold commands
// xxx : Re-enable when trailing comma issue is fully fixed in macro_tools::generic_params::decompose
// #[ derive( Debug, PartialEq, former::Former ) ]
#[ derive( Debug, PartialEq ) ]
// #[ debug ]
// #[ derive( Debug, PartialEq ) ]
pub struct Parent {
  // #[ scalar( setter = false ) ]
  command: HashMap< String, Child >,
}

// Use ChildFormer as custom subformer for ParentFormer to add commands by name.
impl<Definition> ParentFormer<Definition>
where
  Definition: former::FormerDefinition<Storage = <Parent as former::EntityToStorage>::Storage> + 'static,
{
  // more generic version
  #[ inline( always ) ]
  pub fn _children_subform_entry_with_closure<Former2, Definition2, Types2>(self) -> Former2
  where
    Types2: former::FormerDefinitionTypes<Storage = ChildFormerStorage, Formed = Self, Context = Self> + 'static,
    Definition2: former::FormerDefinition<
      Types = Types2,
      End = former::FormingEndClosure<Types2>,
      Storage = ChildFormerStorage,
      Formed = Self,
      Context = Self,
    > + 'static,
    Definition2::End: former::FormingEnd<Definition2::Types>,
    for<'a> Former2: former::FormerBegin<'a, Definition2>,
    Definition2::Storage: 'static,
    Definition2::Context: 'static,
    Definition2::End: 'static,
  {
    let on_end = |substorage: ChildFormerStorage, super_former: core::option::Option<Self>| -> Self {
      let mut super_former = super_former.unwrap();
      if super_former.storage.command.is_none() {
        super_former.storage.command = Some(HashMap::default());
      }
      if let Some(ref mut children) = super_former.storage.command {
        former::CollectionAdd::add(
          children,
          <<HashMap< String, Child > as former::Collection>::Val as former::ValToEntry<HashMap< String, Child >>>::val_to_entry(
            former::StoragePreform::preform(substorage),
          ),
        );
      }
      super_former
    };
    Former2::former_begin(None, Some(self), former::FormingEndClosure::new(on_end))
  }

  // reuse _command_subform_entry
  #[ inline( always ) ]
  pub fn command(self, name: &str) -> ChildAsSubformer<Self, impl ChildAsSubformerEnd<Self>> {
    self._command_subform_entry::<ChildFormer<_>, _>().name(name)
  }

  // that's how you should do custom subformer setters if you can't reuse _command_subform_entry
  #[ inline( always ) ]
  pub fn command2(self, name: &str) -> ChildAsSubformer<Self, impl ChildAsSubformerEnd<Self>> {
    let on_end = |substorage: ChildFormerStorage, super_former: core::option::Option<Self>| -> Self {
      let mut super_former = super_former.unwrap();
      let preformed = former::StoragePreform::preform(substorage);

      if super_former.storage.command.is_none() {
        super_former.storage.command = Some(HashMap::default());
      }

      // add instance to the collection
      super_former
        .storage
        .command
        .as_mut()
        .unwrap()
        .entry(preformed.name.clone())
        .or_insert(preformed.clone());

      // custom logic to add two instances to the collection
      super_former
        .storage
        .command
        .as_mut()
        .unwrap()
        .entry(format!("{}_2", preformed.name))
        .or_insert(preformed.clone());

      super_former
    };
    let subformer = ChildAsSubformer::<Self, _>::begin(None, Some(self), former::FormingEndClosure::new(on_end));
    subformer.name(name)
  }
}

impl former::ValToEntry<HashMap< String, Child >> for Child {
  type Entry = (String, Child);
  #[ inline( always ) ]
  fn val_to_entry(self) -> Self::Entry {
    (self.name.clone(), self)
  }
}

// == Manual implementations for Parent ==

// Parent struct implementations
impl Parent {
  #[ inline( always ) ]
  pub fn former() -> ParentFormer<ParentFormerDefinition<(), Parent, former::ReturnPreformed>> {
    ParentFormer::<ParentFormerDefinition<(), Parent, former::ReturnPreformed>>::new_coercing(former::ReturnPreformed)
  }
}

impl<Definition> former::EntityToFormer<Definition> for Parent
where
  Definition: former::FormerDefinition<Storage = ParentFormerStorage>,
{
  type Former = ParentFormer<Definition>;
}

impl former::EntityToStorage for Parent {
  type Storage = ParentFormerStorage;
}

impl<Context, Formed> former::EntityToDefinitionTypes<Context, Formed> for Parent {
  type Types = ParentFormerDefinitionTypes<Context, Formed>;
}

impl<Context, Formed, End> former::EntityToDefinition<Context, Formed, End> for Parent
where
  End: former::FormingEnd<ParentFormerDefinitionTypes<Context, Formed>>,
{
  type Definition = ParentFormerDefinition<Context, Formed, End>;
  type Types = ParentFormerDefinitionTypes<Context, Formed>;
}

// Parent former definition types
#[ derive( Debug ) ]
pub struct ParentFormerDefinitionTypes<Context = (), Formed = Parent> {
  _phantom: core::marker::PhantomData<(Context, Formed)>,
}

impl<Context, Formed> core::default::Default for ParentFormerDefinitionTypes<Context, Formed> {
  fn default() -> Self {
    Self {
      _phantom: core::marker::PhantomData,
    }
  }
}

impl<Context, Formed> former::FormerDefinitionTypes for ParentFormerDefinitionTypes<Context, Formed> {
  type Storage = ParentFormerStorage;
  type Formed = Formed;
  type Context = Context;
}

impl<Context, Formed> former::FormerMutator for ParentFormerDefinitionTypes<Context, Formed> {}

// Parent former definition
#[ derive( Debug ) ]
pub struct ParentFormerDefinition<Context = (), Formed = Parent, End = former::ReturnPreformed> {
  _phantom: core::marker::PhantomData<(Context, Formed, End)>,
}

impl<Context, Formed, End> core::default::Default for ParentFormerDefinition<Context, Formed, End> {
  fn default() -> Self {
    Self {
      _phantom: core::marker::PhantomData,
    }
  }
}

impl<Context, Formed, End> former::FormerDefinition for ParentFormerDefinition<Context, Formed, End>
where
  End: former::FormingEnd<ParentFormerDefinitionTypes<Context, Formed>>,
{
  type Types = ParentFormerDefinitionTypes<Context, Formed>;
  type End = End;
  type Storage = ParentFormerStorage;
  type Formed = Formed;
  type Context = Context;
}

// Parent storage
pub struct ParentFormerStorage {
  pub command: core::option::Option<HashMap< String, Child >>,
}

impl core::default::Default for ParentFormerStorage {
  #[ inline( always ) ]
  fn default() -> Self {
    Self {
      command: core::option::Option::None,
    }
  }
}

impl former::Storage for ParentFormerStorage {
  type Preformed = Parent;
}

impl former::StoragePreform for ParentFormerStorage {
  fn preform(mut self) -> Self::Preformed {
    let command = if self.command.is_some() {
      self.command.take().unwrap()
    } else {
      Default::default()
    };
    
    Parent { command }
  }
}

// Parent former
pub struct ParentFormer<Definition = ParentFormerDefinition<(), Parent, former::ReturnPreformed>>
where
  Definition: former::FormerDefinition<Storage = ParentFormerStorage>,
  Definition::Types: former::FormerDefinitionTypes<Storage = ParentFormerStorage>,
{
  pub storage: Definition::Storage,
  pub context: core::option::Option<Definition::Context>,
  pub on_end: core::option::Option<Definition::End>,
}

impl<Definition> ParentFormer<Definition>
where
  Definition: former::FormerDefinition<Storage = ParentFormerStorage>,
  Definition::Types: former::FormerDefinitionTypes<Storage = ParentFormerStorage>,
{
  #[ inline( always ) ]
  pub fn new(on_end: Definition::End) -> Self {
    Self::begin_coercing(None, None, on_end)
  }

  #[ inline( always ) ]
  pub fn new_coercing<IntoEnd>(end: IntoEnd) -> Self
  where
    IntoEnd: core::convert::Into<Definition::End>,
  {
    Self::begin_coercing(None, None, end)
  }

  #[ inline( always ) ]
  pub fn begin(
    mut storage: core::option::Option<Definition::Storage>,
    context: core::option::Option<Definition::Context>,
    on_end: <Definition as former::FormerDefinition>::End,
  ) -> Self {
    if storage.is_none() {
      storage = Some(Default::default());
    }
    Self {
      storage: storage.unwrap(),
      context,
      on_end: Some(on_end),
    }
  }

  #[ inline( always ) ]
  pub fn begin_coercing<IntoEnd>(
    mut storage: core::option::Option<Definition::Storage>,
    context: core::option::Option<Definition::Context>,
    on_end: IntoEnd,
  ) -> Self
  where
    IntoEnd: core::convert::Into<<Definition as former::FormerDefinition>::End>,
  {
    if storage.is_none() {
      storage = Some(Default::default());
    }
    Self {
      storage: storage.unwrap(),
      context,
      on_end: Some(on_end.into()),
    }
  }

  #[ inline( always ) ]
  pub fn form(self) -> <Definition::Types as former::FormerDefinitionTypes>::Formed {
    self.end()
  }

  #[ inline( always ) ]
  pub fn end(mut self) -> <Definition::Types as former::FormerDefinitionTypes>::Formed {
    let on_end = self.on_end.take().unwrap();
    let mut context = self.context.take();
    <Definition::Types as former::FormerMutator>::form_mutation(&mut self.storage, &mut context);
    former::FormingEnd::<Definition::Types>::call(&on_end, self.storage, context)
  }

  #[ inline( always ) ]
  pub fn _command_subform_entry<'a, Former2, Definition2>(self) -> Former2
  where
    Former2: former::FormerBegin<'a, Definition2>,
    Definition2: former::FormerDefinition<
      Storage = <Child as former::EntityToStorage>::Storage,
      Formed = Self,
      Context = Self,
      End = ParentSubformEntryCommandEnd<Definition>,
    >,
    Definition: 'a,
    ParentSubformEntryCommandEnd<Definition>:
      former::FormingEnd<<Child as former::EntityToDefinitionTypes<Self, Self>>::Types>,
  {
    Former2::former_begin(None, Some(self), ParentSubformEntryCommandEnd::<Definition>::default())
  }
}

impl<Definition> ParentFormer<Definition>
where
  Definition: former::FormerDefinition<Storage = ParentFormerStorage, Formed = Parent>,
  Definition::Types: former::FormerDefinitionTypes<Storage = ParentFormerStorage, Formed = Parent>,
{
  pub fn preform(self) -> <Definition::Types as former::FormerDefinitionTypes>::Formed {
    former::StoragePreform::preform(self.storage)
  }
}

impl<Definition> ParentFormer<Definition>
where
  Definition: former::FormerDefinition<Storage = ParentFormerStorage, Formed = Parent>,
  Definition::Types: former::FormerDefinitionTypes<Storage = ParentFormerStorage, Formed = Parent>,
{
  #[ inline( always ) ]
  pub fn perform(self) -> Definition::Formed {
    
    self.form()
  }
}

// ParentSubformEntryCommandEnd implementation
#[ derive( Debug ) ]
pub struct ParentSubformEntryCommandEnd<Definition> {
  _phantom: core::marker::PhantomData<Definition>,
}

impl<Definition> Default for ParentSubformEntryCommandEnd<Definition> {
  fn default() -> Self {
    Self {
      _phantom: core::marker::PhantomData,
    }
  }
}

impl<Definition> former::FormingEnd<ChildFormerDefinitionTypes<ParentFormer<Definition>, ParentFormer<Definition>>>
  for ParentSubformEntryCommandEnd<Definition>
where
  Definition: former::FormerDefinition<Storage = ParentFormerStorage>,
{
  #[ inline( always ) ]
  fn call(
    &self,
    storage: ChildFormerStorage,
    super_former: core::option::Option<ParentFormer<Definition>>,
  ) -> ParentFormer<Definition> {
    let mut super_former = super_former.unwrap();
    let preformed = former::StoragePreform::preform(storage);
    if super_former.storage.command.is_none() {
      super_former.storage.command = Some(HashMap::default());
    }
    if let Some(ref mut command) = super_former.storage.command {
      former::CollectionAdd::add(
        command,
        <<HashMap< String, Child > as former::Collection>::Val as former::ValToEntry<HashMap< String, Child >>>::val_to_entry(
          preformed,
        ),
      );
    }
    super_former
  }
}

// FormerBegin implementation for ParentFormer
impl<'storage, Definition> former::FormerBegin<'storage, Definition> for ParentFormer<Definition>
where
  Definition: former::FormerDefinition<Storage = ParentFormerStorage>,
  Definition::Context: 'storage,
  Definition::End: 'storage,
{
  #[ inline( always ) ]
  fn former_begin(
    storage: core::option::Option<Definition::Storage>,
    context: core::option::Option<Definition::Context>,
    on_end: Definition::End,
  ) -> Self {
    Self::begin(storage, context, on_end)
  }
}

// == Manual implementations for Child ==

// Child struct implementations
impl Child {
  #[ inline( always ) ]
  pub fn former() -> ChildFormer<ChildFormerDefinition<(), Child, former::ReturnPreformed>> {
    ChildFormer::<ChildFormerDefinition<(), Child, former::ReturnPreformed>>::new_coercing(former::ReturnPreformed)
  }
}

impl<Definition> former::EntityToFormer<Definition> for Child
where
  Definition: former::FormerDefinition<Storage = ChildFormerStorage>,
{
  type Former = ChildFormer<Definition>;
}

impl former::EntityToStorage for Child {
  type Storage = ChildFormerStorage;
}

impl<Context, Formed> former::EntityToDefinitionTypes<Context, Formed> for Child {
  type Types = ChildFormerDefinitionTypes<Context, Formed>;
}

impl<Context, Formed, End> former::EntityToDefinition<Context, Formed, End> for Child
where
  End: former::FormingEnd<ChildFormerDefinitionTypes<Context, Formed>>,
{
  type Definition = ChildFormerDefinition<Context, Formed, End>;
  type Types = ChildFormerDefinitionTypes<Context, Formed>;
}

// Child former definition types
#[ derive( Debug ) ]
pub struct ChildFormerDefinitionTypes<Context = (), Formed = Child> {
  _phantom: core::marker::PhantomData<(Context, Formed)>,
}

impl<Context, Formed> core::default::Default for ChildFormerDefinitionTypes<Context, Formed> {
  fn default() -> Self {
    Self {
      _phantom: core::marker::PhantomData,
    }
  }
}

impl<Context, Formed> former::FormerDefinitionTypes for ChildFormerDefinitionTypes<Context, Formed> {
  type Storage = ChildFormerStorage;
  type Formed = Formed;
  type Context = Context;
}

impl<Context, Formed> former::FormerMutator for ChildFormerDefinitionTypes<Context, Formed> {}

// Child former definition
#[ derive( Debug ) ]
pub struct ChildFormerDefinition<Context = (), Formed = Child, End = former::ReturnPreformed> {
  _phantom: core::marker::PhantomData<(Context, Formed, End)>,
}

impl<Context, Formed, End> core::default::Default for ChildFormerDefinition<Context, Formed, End> {
  fn default() -> Self {
    Self {
      _phantom: core::marker::PhantomData,
    }
  }
}

impl<Context, Formed, End> former::FormerDefinition for ChildFormerDefinition<Context, Formed, End>
where
  End: former::FormingEnd<ChildFormerDefinitionTypes<Context, Formed>>,
{
  type Types = ChildFormerDefinitionTypes<Context, Formed>;
  type End = End;
  type Storage = ChildFormerStorage;
  type Formed = Formed;
  type Context = Context;
}

// Child storage
pub struct ChildFormerStorage {
  pub name: core::option::Option<String>,
  pub description: core::option::Option<String>,
}

impl core::default::Default for ChildFormerStorage {
  #[ inline( always ) ]
  fn default() -> Self {
    Self {
      name: core::option::Option::None,
      description: core::option::Option::None,
    }
  }
}

impl former::Storage for ChildFormerStorage {
  type Preformed = Child;
}

impl former::StoragePreform for ChildFormerStorage {
  fn preform(mut self) -> Self::Preformed {
    let name = if self.name.is_some() {
      self.name.take().unwrap()
    } else {
      Default::default()
    };
    let description = if self.description.is_some() {
      self.description.take().unwrap()
    } else {
      Default::default()
    };
    
    Child { name, description }
  }
}

// Child former
pub struct ChildFormer<Definition = ChildFormerDefinition<(), Child, former::ReturnPreformed>>
where
  Definition: former::FormerDefinition<Storage = ChildFormerStorage>,
  Definition::Types: former::FormerDefinitionTypes<Storage = ChildFormerStorage>,
{
  pub storage: Definition::Storage,
  pub context: core::option::Option<Definition::Context>,
  pub on_end: core::option::Option<Definition::End>,
}

impl<Definition> ChildFormer<Definition>
where
  Definition: former::FormerDefinition<Storage = ChildFormerStorage>,
  Definition::Types: former::FormerDefinitionTypes<Storage = ChildFormerStorage>,
{
  #[ inline( always ) ]
  pub fn new(on_end: Definition::End) -> Self {
    Self::begin_coercing(None, None, on_end)
  }

  #[ inline( always ) ]
  pub fn new_coercing<IntoEnd>(end: IntoEnd) -> Self
  where
    IntoEnd: core::convert::Into<Definition::End>,
  {
    Self::begin_coercing(None, None, end)
  }

  #[ inline( always ) ]
  pub fn begin(
    mut storage: core::option::Option<Definition::Storage>,
    context: core::option::Option<Definition::Context>,
    on_end: <Definition as former::FormerDefinition>::End,
  ) -> Self {
    if storage.is_none() {
      storage = Some(Default::default());
    }
    Self {
      storage: storage.unwrap(),
      context,
      on_end: Some(on_end),
    }
  }

  #[ inline( always ) ]
  pub fn begin_coercing<IntoEnd>(
    mut storage: core::option::Option<Definition::Storage>,
    context: core::option::Option<Definition::Context>,
    on_end: IntoEnd,
  ) -> Self
  where
    IntoEnd: core::convert::Into<<Definition as former::FormerDefinition>::End>,
  {
    if storage.is_none() {
      storage = Some(Default::default());
    }
    Self {
      storage: storage.unwrap(),
      context,
      on_end: Some(on_end.into()),
    }
  }

  #[ inline( always ) ]
  pub fn form(self) -> <Definition::Types as former::FormerDefinitionTypes>::Formed {
    self.end()
  }

  #[ inline( always ) ]
  pub fn end(mut self) -> <Definition::Types as former::FormerDefinitionTypes>::Formed {
    let on_end = self.on_end.take().unwrap();
    let mut context = self.context.take();
    <Definition::Types as former::FormerMutator>::form_mutation(&mut self.storage, &mut context);
    former::FormingEnd::<Definition::Types>::call(&on_end, self.storage, context)
  }

  #[ inline( always ) ]
  pub fn name(mut self, src: impl Into<String>) -> Self {
    debug_assert!(self.storage.name.is_none());
    self.storage.name = Some(src.into());
    self
  }

  #[ inline( always ) ]
  pub fn description(mut self, src: impl Into<String>) -> Self {
    debug_assert!(self.storage.description.is_none());
    self.storage.description = Some(src.into());
    self
  }
}

impl<Definition> ChildFormer<Definition>
where
  Definition: former::FormerDefinition<Storage = ChildFormerStorage, Formed = Child>,
  Definition::Types: former::FormerDefinitionTypes<Storage = ChildFormerStorage, Formed = Child>,  
{
  pub fn preform(self) -> <Definition::Types as former::FormerDefinitionTypes>::Formed {
    former::StoragePreform::preform(self.storage)
  }
}

impl<Definition> ChildFormer<Definition>
where
  Definition: former::FormerDefinition<Storage = ChildFormerStorage, Formed = Child>,
  Definition::Types: former::FormerDefinitionTypes<Storage = ChildFormerStorage, Formed = Child>,
{
  #[ inline( always ) ]
  pub fn perform(self) -> Definition::Formed {
    
    self.form()
  }
}

// Type aliases for subformer functionality
pub type ChildAsSubformer<Superformer, End> = ChildFormer<ChildFormerDefinition<Superformer, Superformer, End>>;

pub trait ChildAsSubformerEnd<SuperFormer>: former::FormingEnd<ChildFormerDefinitionTypes<SuperFormer, SuperFormer>> {}

impl<SuperFormer, T> ChildAsSubformerEnd<SuperFormer> for T
where
  T: former::FormingEnd<ChildFormerDefinitionTypes<SuperFormer, SuperFormer>>,
{}

// FormerBegin implementation for ChildFormer
impl<'storage, Definition> former::FormerBegin<'storage, Definition> for ChildFormer<Definition>
where
  Definition: former::FormerDefinition<Storage = ChildFormerStorage>,
  Definition::Context: 'storage,
  Definition::End: 'storage,
{
  #[ inline( always ) ]
  fn former_begin(
    storage: core::option::Option<Definition::Storage>,
    context: core::option::Option<Definition::Context>,
    on_end: Definition::End,
  ) -> Self {
    Self::begin(storage, context, on_end)
  }
}

#[ test ]
fn custom1() {
  let got = Parent::former()
  .command( "echo" )
    .description( "prints all subjects and properties" ) // sets additional properties using custom subformer
    .end()
  .command( "exit" )
    .description( "just exit" ) // Sets additional properties using using custom subformer
    .end()
  .form();

  let got = got
    .command
    .iter()
    .map(|e| e.0)
    .cloned()
    .collect::<collection_tools::HashSet< String >>();
  let exp: collection_tools::HashSet<String> = collection_tools::hset!["echo".into(), "exit".into(),];
  a_id!(got, exp);
}

#[ test ]
fn custom2() {
  let got = Parent::former()
  .command2( "echo" )
    .description( "prints all subjects and properties" ) // sets additional properties using custom subformer
    .end()
  .command2( "exit" )
    .description( "just exit" ) // Sets additional properties using using custom subformer
    .end()
  .form();

  let got = got
    .command
    .iter()
    .map(|e| e.0)
    .cloned()
    .collect::<collection_tools::HashSet< String >>();
  let exp: collection_tools::HashSet<String> = collection_tools::hset!["echo".into(), "echo_2".into(), "exit".into(), "exit_2".into(),];
  a_id!(got, exp);
}