devela/data/table/value/macros/
define_each.rs

1// devela::data::table::value::macros::define_each
2//
3//!
4//
5// TOC
6// - define_data_value!
7// - define_data_type!
8// - define_data_raw!
9
10/// for defining enum DataValue*
11//
12// macro args for variants
13// - $C_+   :    copy variants
14// - $N_+   : noncopy variants
15// - _doc*  :
16// - _name* :
17// - _type* :
18// - _dep*  :
19// - _ptr*  :
20#[allow(unused_macros)]
21macro_rules! define_data_value {
22    (
23        v: $Value:ident, t: $Type:ident, r: $Raw:ident,
24        size: $b:literal, feature: $feature:literal,
25
26        copy:
27            $( $C_doc:literal, $C_name:ident, $C_type:ty,
28               [def:$C_def:stmt]
29            )* ;
30        copy@dep:
31            $( $C_doc_dep:literal, $C_name_dep:ident, $C_type_dep:ty,
32               $C_dep1_dep:literal, $C_dep2_dep:literal,
33               [def:$C_def_dep:stmt]
34            )* ;
35        copy@ptr:
36            $( $C_doc_ptr:literal, $C_name_ptr:ident, $C_type_ptr:ty,
37               $C_ptr_ptr:meta,
38               [def:$C_def_ptr:stmt]
39            )* ;
40        copy@ptrdep:
41            $( $C_doc_ptrdep:literal, $C_name_ptrdep:ident, $C_type_ptrdep:ty,
42               $C_ptr_ptrdep:meta, $C_dep1_ptrdep:literal, $C_dep2_ptrdep:literal,
43               [def:$C_def_ptrdep:stmt]
44             )* ;
45
46        noncopy:
47            $( $N_doc:literal, $N_name:ident, $N_type:ty,
48               [def:$N_def:stmt]
49            )* ;
50        noncopy@dep:
51            $( $N_doc_dep:literal, $N_name_dep:ident, $N_type_dep:ty,
52               $N_dep1_dep:literal, $N_dep2_dep:literal,
53               [def:$N_def_dep:stmt]
54            )* ;
55        noncopy@ptr:
56            $( $N_doc_ptr:literal, $N_name_ptr:ident, $N_type_ptr:ty,
57               $N_ptr_ptr:meta, $N_dep1_ptr:literal, $N_dep2_ptr:literal,
58               [def:$N_def_ptr:stmt]
59            )* ;
60        noncopy@ptrdep:
61            $( $N_doc_ptrdep:literal, $N_name_ptrdep:ident, $N_type_ptrdep:ty,
62               $N_ptr_ptrdep:meta, $N_dep1_ptrdep:literal, $N_dep2_ptrdep:literal,
63               [def:$N_def_ptrdep:stmt]
64            )* ;
65    ) => { $crate::paste! {
66        // ## copy version (DataValue)
67        // -----------------------------------------------------------------
68        #[doc = $b "-bit data *value*, restricted to `Copy` variants, with extra `V`." ]
69        ///
70        /// See also:
71        #[doc = "- [" [<$Type $b Copy With>] "]" ]
72        #[doc = "- [" [<$Value $b With>] "][" [<$Value $b With>] "] -Copy" ]
73        #[doc = "- [" [<$Value $b Copy>] "][" [<$Value $b Copy>] "] -With" ]
74        #[doc = "- [" [<$Value $b>] "][" [<$Value $b>] "] -Copy -With" ]
75        #[derive(Clone, Copy, Debug, PartialEq)]
76        #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = $feature)))]
77        pub enum [<$Value $b Copy With>]<V: DataValue> {
78            /// Represents the absence of *data*.
79            None,
80            /// Extra *data values*.
81            Extra(V),
82
83            $( // fundamental types
84                #[doc = $C_doc]
85                $C_name($C_type),
86            )*
87
88            $( // pointer-size dependant
89                #[cfg($C_ptr_ptr)]
90                #[doc = $C_doc_ptr]
91                $C_name_ptr($C_type_ptr),
92            )*
93
94            $( // feature-gated dependencies
95                #[cfg(all(feature = $C_dep1_dep, feature = $C_dep2_dep))]
96                #[cfg_attr(feature = "nightly_doc",
97                    doc(cfg(all(feature = $C_dep1_dep,
98                                feature = $C_dep2_dep))))]
99                #[doc = $C_doc_dep]
100                $C_name_dep($C_type_dep),
101            )*
102
103            $( // pointer-size & feature-gated dependencies
104                #[cfg(all($C_ptr_ptrdep,
105                        feature = $C_dep1_ptrdep,
106                        feature = $C_dep2_ptrdep))]
107                #[cfg_attr(feature = "nightly_doc",
108                    doc(cfg(all(feature = $C_dep1_ptrdep,
109                                feature = $C_dep2_ptrdep))))]
110                #[doc = $C_doc_ptrdep]
111                $C_name_ptrdep($C_type_ptrdep),
112            )*
113        }
114
115        // DataValue Copy (-With) alias
116        #[doc = $b "-bit data *value*, restricted to `Copy` variants." ]
117        ///
118        /// See also:
119        #[doc = "- [" [<$Type $b Copy>] "]" ]
120        #[doc = "- [" [<$Value $b>] "][" [<$Value $b>] "] -Copy" ]
121        #[doc = "- [" [<$Value $b Copy With>] "][" [<$Value $b Copy With>] "] +With" ]
122        #[doc = "- [" [<$Value $b With>] "][" [<$Value $b With>] "] -Copy +With" ]
123        #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = $feature)))]
124        pub type [<$Value $b Copy>] = [< $Value $b Copy With>]<$crate::NoData>;
125
126        // implement the DataValue trait
127        $crate::impl_data_value![
128            v: [< $Value $b Copy With >], DataValue,
129            t: [< $Type $b Copy With >], DataType,
130            all_are_copy: true,
131
132            copy:
133                $( $C_name, $C_type
134                ),* ;
135            copy@dep:
136                $( $C_name_dep, $C_type_dep,
137                   $C_dep1_dep, $C_dep2_dep
138                ),* ;
139            copy@ptr:
140                $( $C_name_ptr, $C_type_ptr,
141                   $C_ptr_ptr
142                ),* ;
143            copy@ptrdep:
144                $( $C_name_ptrdep, $C_type_ptrdep,
145                   $C_ptr_ptrdep,
146                   $C_dep1_ptrdep, $C_dep2_ptrdep
147                ),* ;
148
149            noncopy: ;
150            noncopy@dep: ;
151            noncopy@ptr: ;
152            noncopy@ptrdep: ;
153        ];
154        impl<V: DataValueCopy> DataValueCopy for [< $Value $b Copy With >]<V> { }
155
156        // ## non-copy version (DataValue)
157        // -----------------------------------------------------------------
158        #[doc = $b "-bit data *value*, with extra `V`." ]
159        ///
160        /// See also:
161        #[doc = "- [" [<$Type $b With>] "]" ]
162        #[doc = "- [" [<$Value $b Copy With>] "][" [<$Value $b Copy With>] "] +Copy" ]
163        #[doc = "- [" [<$Value $b>] "][" [<$Value $b>] "] -Width" ]
164        #[doc = "- [" [<$Value $b Copy>] "][" [<$Value $b Copy>] "] +Copy -Width" ]
165        #[derive(Clone, Debug, PartialEq)]
166        #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = $feature)))]
167        pub enum [<$Value $b With>]<V: DataValue> {
168            /// Represents the absence of *data*.
169            None,
170            /// Extra *data values*.
171            Extra(V),
172
173            $( // fundamental types
174                #[doc = $C_doc]
175                $C_name($C_type),
176            )*
177            $(
178                #[doc = $N_doc]
179                $N_name($N_type),
180            )*
181
182            $( // pointer-size dependant
183                #[cfg($C_ptr_ptr)]
184                #[doc = $C_doc_ptr]
185                $C_name_ptr($C_type_ptr),
186            )*
187            $(
188                #[cfg($N_ptr_ptr)]
189                #[doc = $N_doc_ptr]
190                $N_name_ptr($N_type_ptr),
191            )*
192
193            $( // feature-gated dependencies
194                #[cfg(all(feature = $C_dep1_dep, feature = $C_dep2_dep))]
195                #[cfg_attr(feature = "nightly_doc",
196                    doc(cfg(all(feature = $C_dep1_dep, feature = $C_dep2_dep))))]
197                #[doc = $C_doc_dep]
198                $C_name_dep($C_type_dep),
199            )*
200            $(
201                #[cfg(all(feature = $N_dep1_dep, feature = $N_dep2_dep))]
202                #[cfg_attr(feature = "nightly_doc",
203                    doc(cfg(all(feature = $N_dep1_dep, feature = $N_dep2_dep))))]
204                #[doc = $N_doc_dep]
205                $N_name_dep($N_type_dep),
206            )*
207
208            $( // pointer-size & feature-gated dependencies
209                #[cfg(all($C_ptr_ptrdep,
210                        feature = $C_dep1_ptrdep,
211                        feature = $C_dep2_ptrdep))]
212                #[cfg_attr(feature = "nightly_doc",
213                    doc(cfg(all(feature = $C_dep1_ptrdep,
214                                feature = $C_dep2_ptrdep))))]
215                #[doc = $C_doc_ptrdep]
216                $C_name_ptrdep($C_type_ptrdep),
217            )*
218            $(
219                #[cfg(all($N_ptr_ptrdep,
220                        feature = $N_dep1_ptrdep,
221                        feature = $N_dep2_ptrdep))]
222                #[cfg_attr(feature = "nightly_doc",
223                    doc(cfg(all(feature = $N_dep1_ptrdep,
224                                feature = $N_dep2_ptrdep))))]
225                #[doc = $N_doc_ptrdep]
226                $N_name_ptrdep($N_type_ptrdep),
227            )*
228        }
229
230        // alias DataValue
231        #[doc = $b "-bit data *value*." ]
232        ///
233        /// See also:
234        #[doc = "- [" [<$Type $b>] "]" ]
235        #[doc = "- [" [<$Value $b Copy>] "][" [<$Value $b Copy>] "] +Copy" ]
236        #[doc = "- [" [<$Value $b With>] "][" [<$Value $b With>] "] +With" ]
237        #[doc = "- [" [<$Value $b Copy With>] "][" [<$Value $b Copy With>] "] +Copy +With" ]
238        #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = $feature)))]
239        pub type [<$Value $b>] = [< $Value $b With>]<$crate::NoData>;
240
241        // implement the DataValue trait
242        $crate::impl_data_value![
243            v: [< $Value $b With >], DataValue,
244            t: [< $Type $b With >], DataType,
245            all_are_copy: false,
246
247            copy:
248                $( $C_name, $C_type
249                ),* ;
250            copy@dep:
251                $( $C_name_dep, $C_type_dep,
252                   $C_dep1_dep, $C_dep2_dep
253                ),* ;
254            copy@ptr:
255                $( $C_name_ptr, $C_type_ptr,
256                   $C_ptr_ptr
257                ),* ;
258            copy@ptrdep:
259                $( $C_name_ptrdep, $C_type_ptrdep,
260                   $C_ptr_ptrdep,
261                   $C_dep1_ptrdep, $C_dep2_ptrdep
262                ),* ;
263
264            noncopy:
265                $( $N_name, $N_type
266                ),* ;
267            noncopy@dep:
268                $( $N_name_dep, $N_type_dep,
269                   $N_dep1_dep, $N_dep2_dep
270                ),* ;
271            noncopy@ptr:
272                $( $N_name_ptr, $N_type_ptr,
273                   $N_ptr_ptr
274                ),* ;
275            noncopy@ptrdep:
276                $( $N_name_ptrdep, $N_type_ptrdep,
277                   $N_ptr_ptrdep,
278                   $N_dep1_ptrdep, $N_dep2_ptrdep
279                ),* ;
280        ];
281
282        // implement `TryFrom`<`DataValue`> for *contained-value*:
283
284        $( // Copy
285            impl<V: DataValueCopy> TryFrom<[<$Value $b Copy With>]<V>> for $C_type {
286                type Error = ();
287                fn try_from(v: [<$Value $b Copy With>]<V>) -> Result<Self, Self::Error> {
288                    match v {
289                        [<$Value $b Copy With>]::$C_name(v) => Ok(v),
290                        _ => Err(()),
291                    }
292                }
293            }
294        )*
295        $( // Copy feature-bound
296            #[cfg(all(feature = $C_dep1_dep, feature = $C_dep2_dep ))]
297            impl<V: DataValue> TryFrom<[<$Value $b With>]<V>> for $C_type_dep {
298                type Error = ();
299                fn try_from(v: [<$Value $b With>]<V>) -> Result<Self, Self::Error> {
300                    match v {
301                        [<$Value $b With>]::$C_name_dep(v) => Ok(v),
302                        _ => Err(()),
303                    }
304                }
305            }
306        )*
307        $( // non-Copy
308            impl<V: DataValue> TryFrom<[<$Value $b With>]<V>> for $N_type {
309                type Error = ();
310                fn try_from(v: [<$Value $b With>]<V>) -> Result<Self, Self::Error> {
311                    match v {
312                        [<$Value $b With>]::$N_name(v) => Ok(v),
313                        _ => Err(()),
314                    }
315                }
316            }
317        )*
318        $( // non-Copy feature-bound
319            #[cfg(all(feature = $N_dep1_dep, feature = $N_dep2_dep ))]
320            impl<V: DataValue> TryFrom<[<$Value $b With>]<V>> for $N_type_dep {
321                type Error = ();
322                fn try_from(v: [<$Value $b With>]<V>) -> Result<Self, Self::Error> {
323                    match c {
324                        [<$Value $b With>]::$N_name_dep(v) => Ok(v),
325                        _ => Err(()),
326                    }
327                }
328            }
329        )*
330
331        // implement `From`<*contained-value*> for `DataValue`:
332
333        $( // Copy
334            impl<V: DataValueCopy> From<$C_type> for [<$Value $b Copy With>]<V> {
335                fn from(v: $C_type) -> Self {
336                    [<$Value $b Copy With>]::$C_name(v)
337                }
338            }
339        )*
340        $( // Copy feature-bound
341            #[cfg(all(feature = $C_dep1_dep, feature = $C_dep2_dep ))]
342            impl<V: DataValueCopy> From<$C_type_dep> for [<$Value $b Copy With>]<V> {
343                fn from(v: $C_type_dep) -> Self {
344                    [<$Value $b Copy With>]::$C_name_dep(v)
345                }
346            }
347        )*
348        $( // non-Copy
349            impl<V: DataValue> From<$N_type> for [<$Value $b With>]<V> {
350                fn from(v: $N_type) -> Self {
351                    [<$Value $b With>]::$N_name(v)
352                }
353            }
354        )*
355        $( // non-Copy feature-bound
356            #[cfg(all(feature = $N_dep1_dep, feature = $N_dep2_dep ))]
357            impl<V: DataValue> From<$N_type_dep> for [<$Value $b With>]<V> {
358                fn from(v: $N_type_dep) -> Self {
359                    [<$Value $b With>]::$N_name_dep(v)
360                }
361            }
362        )*
363
364        // from DataValue to DataRawCopy
365        #[cfg(all(not(feature = "safe_data"), feature = "unsafe_layout"))]
366        #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "unsafe_layout")))]
367        impl<V: DataValueCopy> From<[<$Value $b Copy With>]<V>> for [<$Raw $b Copy>] {
368            fn from(cell: [<$Value $b Copy With>]<V>) -> Self {
369                match cell {
370                    [<$Value $b Copy With>]::None => Self { None: () },
371                    [<$Value $b Copy With>]::Extra(_) => Self { None: () }, // FIX:IMPROVE
372
373                    $( // fundamental types
374                        [<$Value $b Copy With>]::$C_name(v) => Self { $C_name: v },
375                    )*
376
377                    $( // pointer-size dependant
378                        #[cfg($C_ptr_ptr)]
379                        [<$Value $b Copy With>]::$C_name_ptr(v) => Self { $C_name_ptr: v },
380                    )*
381
382                    $( // feature-gated dependencies
383                        #[cfg(all(feature = $C_dep1_dep, feature = $C_dep2_dep))]
384                        [<$Value $b Copy With>]::$C_name_dep(v) => Self { $C_name_dep: v },
385                    )*
386                }
387            }
388        }
389    }};
390}
391#[allow(unused_imports)]
392pub(crate) use define_data_value;
393/// for defining enum DataType*
394#[allow(unused_macros)]
395macro_rules! define_data_type {
396    (
397        v: $Value:ident, t: $Type:ident, r: $Raw:ident,
398        size: $b:literal, feature: $feature:literal,
399
400        copy:
401            $( $C_doc:literal, $C_name:ident, $C_type:ty,
402               [def:$C_def:stmt]
403            )* ;
404        copy@dep:
405            $( $C_doc_dep:literal, $C_name_dep:ident, $C_type_dep:ty,
406               $C_dep1_dep:literal, $C_dep2_dep:literal,
407               [def:$C_def_dep:stmt]
408            )* ;
409        copy@ptr:
410            $( $C_doc_ptr:literal, $C_name_ptr:ident, $C_type_ptr:ty,
411               $C_ptr_ptr:meta,
412               [def:$C_def_ptr:stmt]
413            )* ;
414        copy@ptrdep:
415            $( $C_doc_ptrdep:literal, $C_name_ptrdep:ident, $C_type_ptrdep:ty,
416               $C_ptr_ptrdep:meta, $C_dep1_ptrdep:literal, $C_dep2_ptrdep:literal,
417               [def:$C_def_ptrdep:stmt]
418            )* ;
419
420        noncopy:
421            $( $N_doc:literal, $N_name:ident, $N_type:ty,
422               [def:$N_def:stmt]
423            )* ;
424        noncopy@dep:
425            $( $N_doc_dep:literal, $N_name_dep:ident, $N_type_dep:ty,
426               $N_dep1_dep:literal, $N_dep2_dep:literal,
427               [def:$N_def_dep:stmt]
428            )* ;
429        noncopy@ptr:
430            $( $N_doc_ptr:literal, $N_name_ptr:ident, $N_type_ptr:ty,
431               $N_ptr_ptr:meta, $N_dep1_ptr:literal, $N_dep2_ptr:literal,
432               [def:$N_def_ptr:stmt]
433            )* ;
434        noncopy@ptrdep:
435            $( $N_doc_ptrdep:literal, $N_name_ptrdep:ident, $N_type_ptrdep:ty,
436               $N_ptr_ptrdep:meta, $N_dep1_ptrdep:literal, $N_dep2_ptrdep:literal,
437               [def:$N_def_ptrdep:stmt]
438            )* ;
439    ) =>  { $crate::paste! {
440        // ## copy version (DataType)
441        // -----------------------------------------------------------------
442        #[doc = $b "-bit data *type*, restricted to `Copy` variants, with extra `T`." ]
443        ///
444        /// See also:
445        #[doc = "- [" [<$Value $b Copy With>] "]" ]
446        #[doc = "- [" [<$Type $b With>]  "][" [<$Type $b With>] "] -Copy" ]
447        #[doc = "- [" [<$Type $b Copy>]  "][" [<$Type $b Copy>] "] -With" ]
448        #[doc = "- [" [<$Type $b>]  "][" [<$Type $b>] "] -Copy -With" ]
449        #[derive(Clone, Copy, Debug, PartialEq)]
450        #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = $feature)))]
451        pub enum [< $Type $b Copy With >]<T: DataType> {
452            /// Represents the absence of *data*.
453            None,
454            /// A custom *data type* extension.
455            Extra(T),
456
457            $( // fundamental types
458                #[doc = $C_doc ]
459                $C_name,
460            )*
461
462            $( // pointer-size dependant
463                #[cfg($C_ptr_ptr)]
464                #[doc = $C_doc_ptr]
465                $C_name_ptr,
466            )*
467
468            $( // feature-gated dependencies
469                #[cfg(all(feature = $C_dep1_dep, feature = $C_dep2_dep))]
470                #[cfg_attr(feature = "nightly_doc",
471                    doc(cfg(all(feature = $C_dep1_dep,
472                                feature = $C_dep2_dep))))]
473                #[doc = $C_doc_dep]
474                $C_name_dep,
475            )*
476
477            $( // pointer-size & feature-gated dependencies
478                #[cfg(all($C_ptr_ptrdep,
479                        feature = $C_dep1_ptrdep,
480                        feature = $C_dep2_ptrdep))]
481                #[cfg_attr(feature = "nightly_doc",
482                    doc(cfg(all(feature = $C_dep1_ptrdep,
483                                feature = $C_dep2_ptrdep))))]
484                #[doc = $C_doc_ptrdep]
485                $C_name_ptrdep,
486            )*
487        }
488
489        // DataType Copy (-With) alias
490        #[doc = $b "-bit data *type*, restricted to `Copy` variants." ]
491        ///
492        /// See also:
493        #[doc = "- [" [<$Value $b Copy>] "]" ]
494        #[doc = "- [" [<$Type $b>] "][" [<$Type $b>] "] -Copy" ]
495        #[doc = "- [" [<$Type $b Copy With>] "][" [<$Type $b Copy With>] "] +With" ]
496        #[doc = "- [" [<$Type $b With>] "][" [<$Type $b With>] "] -Copy +With" ]
497        #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = $feature)))]
498        pub type [<$Type $b Copy>] = [< $Type $b Copy With>]<$crate::NoData>;
499
500        // implement the DataType trait
501        $crate::impl_data_type![
502            v: [< $Value $b Copy With >], DataValue,
503            t: [< $Type $b Copy With >], DataType,
504            all_are_copy: true,
505
506            copy:
507                $( $C_name, $C_type,
508                   [def:$C_def]
509                )* ;
510            copy@dep:
511                $( $C_name_dep, $C_type_dep,
512                   $C_dep1_dep, $C_dep2_dep,
513                   [def:$C_def_dep]
514                )* ;
515            copy@ptr:
516                $( $C_name_ptr, $C_type_ptr,
517                   $C_ptr_ptr,
518                   [def:$C_def_ptr]
519                )* ;
520            copy@ptrdep:
521                $( $C_name_ptrdep, $C_type_ptrdep,
522                   $C_ptr_ptrdep,
523                   $C_dep1_ptrdep, $C_dep2_ptrdep,
524                   [def:$C_def_ptrdep]
525                )* ;
526
527            noncopy: ;
528            noncopy@dep: ;
529            noncopy@ptr: ;
530            noncopy@ptrdep: ;
531        ];
532        impl<T: DataTypeCopy> DataTypeCopy for [< $Type $b Copy With >]<T>
533            where T::Value: DataValueCopy {}
534
535        // ## non-copy version (DataType)
536        // -----------------------------------------------------------------
537        #[doc = $b "-bit data *type*, with extra `T`." ]
538        ///
539        /// See also:
540        #[doc = "- [" [<$Value $b With>] "]" ]
541        #[doc = "- [" [<$Type $b Copy With>] "][" [<$Type $b Copy With>] "] +Copy" ]
542        #[doc = "- [" [<$Type $b>] "][" [<$Type $b>] "] -With" ]
543        #[doc = "- [" [<$Type $b Copy>] "][" [<$Type $b Copy>] "] +Copy -With" ]
544        #[derive(Clone, Copy, Debug, PartialEq)]
545        #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = $feature)))]
546        pub enum [< $Type $b With >]<T: DataType> {
547            /// Represents the absence of *data*.
548            None,
549            /// A custom *data type* extension.
550            Extra(T),
551
552            $( // fundamental types
553                #[doc = $C_doc ]
554                $C_name,
555            )*
556            $(
557                #[doc = $N_doc ]
558                $N_name,
559            )*
560
561            $( // pointer-size dependant
562                #[cfg($C_ptr_ptr)]
563                #[doc = $C_doc_ptr]
564                $C_name_ptr,
565            )*
566            $(
567                #[cfg($N_ptr_ptr)]
568                #[doc = $N_doc_ptr]
569                $N_name_ptr,
570            )*
571
572            $( // feature-gated dependencies
573                #[cfg(all(feature = $C_dep1_dep, feature = $C_dep2_dep))]
574                #[cfg_attr(feature = "nightly_doc",
575                    doc(cfg(all(feature = $C_dep1_dep,
576                                feature = $C_dep2_dep))))]
577                #[doc = $C_doc_dep]
578                $C_name_dep,
579            )*
580            $(
581                #[cfg(all(feature = $N_dep1_dep, feature = $N_dep2_dep))]
582                #[cfg_attr(feature = "nightly_doc",
583                    doc(cfg(all(feature = $N_dep1_dep,
584                                feature = $N_dep2_dep))))]
585                #[doc = $N_doc_dep]
586                $N_name_dep,
587            )*
588            $( // pointer-size & feature-gated dependencies
589                #[cfg(all($C_ptr_ptrdep,
590                        feature = $C_dep1_ptrdep,
591                        feature = $C_dep2_ptrdep))]
592                #[cfg_attr(feature = "nightly_doc",
593                    doc(cfg(all(feature = $C_dep1_ptrdep,
594                                feature = $C_dep2_ptrdep))))]
595                #[doc = $C_doc_ptrdep]
596                $C_name_ptrdep,
597            )*
598            $(
599                #[cfg(all($N_ptr_ptrdep,
600                        feature = $N_dep1_ptrdep,
601                        feature = $N_dep2_ptrdep))]
602                #[cfg_attr(feature = "nightly_doc",
603                    doc(cfg(all(feature = $N_dep1_ptrdep,
604                                feature = $N_dep2_ptrdep))))]
605                #[doc = $N_doc_ptrdep]
606                $N_name_ptrdep,
607            )*
608        }
609
610        // DataType (-With) alias
611        #[doc = $b "-bit data *type*"]
612        ///
613        /// See also:
614        #[doc = "- [" [<$Value $b>] "]" ]
615        #[doc = "- [" [<$Type $b Copy>] "][" [<$Type $b Copy>] "] +Copy" ]
616        #[doc = "- [" [<$Type $b With>] "][" [<$Type $b With>] "] +With" ]
617        #[doc = "- [" [<$Type $b Copy With>] "][" [<$Type $b Copy With>] "] +Copy +With" ]
618        #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = $feature)))]
619        pub type [<$Type $b>] = [< $Type $b With>]<$crate::NoData>;
620
621        // implement the DataType trait
622        $crate::impl_data_type![
623            v: [< $Value $b With >], DataValue,
624            t: [< $Type $b With >], DataType,
625            all_are_copy: false,
626
627            copy:
628                $( $C_name, $C_type,
629                   [def:$C_def]
630                )* ;
631            copy@dep:
632                $( $C_name_dep, $C_type_dep,
633                   $C_dep1_dep, $C_dep2_dep,
634                   [def:$C_def_dep]
635                )* ;
636            copy@ptr:
637                $( $C_name_ptr, $C_type_ptr,
638                   $C_ptr_ptr,
639                   [def:$C_def_ptr]
640                )* ;
641            copy@ptrdep:
642                $( $C_name_ptrdep, $C_type_ptrdep,
643                   $C_ptr_ptrdep,
644                   $C_dep1_ptrdep, $C_dep2_ptrdep,
645                   [def:$C_def_ptrdep]
646                )* ;
647
648            noncopy:
649                $($N_name, $N_type,
650                   [def:$N_def]
651                )* ;
652            noncopy@dep:
653                $( $N_name_dep, $N_type_dep,
654                   $N_dep1_dep, $N_dep2_dep,
655                   [def:$N_def_dep]
656                )* ;
657            noncopy@ptr:
658                $( $N_name_ptr, $N_type_ptr,
659                   $N_ptr_ptr,
660                   [def:$N_def_ptr]
661                )* ;
662            noncopy@ptrdep:
663                $( $N_name_ptrdep, $N_type_ptrdep,
664                   $N_ptr_ptrdep,
665                   $N_dep1_ptrdep, $N_dep2_ptrdep,
666                   [def:$N_def_ptrdep]
667                )* ;
668        ];
669    }};
670}
671#[allow(unused_imports)]
672pub(crate) use define_data_type;
673
674/// Defines the `DataRaw*` union.
675///
676/// It calls the macros: `impl_raw!`
677// NOTES:
678// - https://doc.rust-lang.org/stable/reference/items/unions.html
679// - https://doc.rust-lang.org/std/mem/struct.ManuallyDrop.html
680// - [non-Copy](https://github.com/rust-lang/rust/issues/55149)
681// DONE:1.64: refs in unions https://github.com/rust-lang/rust/pull/97995 (closed 55149)
682// WAIT? https://github.com/rust-lang/rust/issues/98102
683// IMPROVE:
684// - support With version (generics are supported I THINK)
685// - support non-Copy types by wrapping with ManuallyDrop<T>.
686// - add a not so unsafe api for first use cases, (space efficient rows).
687#[allow(unused_macros)]
688macro_rules! define_data_raw {
689    (
690        v: $Value:ident, t: $Type:ident, r: $Raw:ident,
691        size: $b:literal, feature: $feature:literal,
692
693        copy:
694            $( $C_doc:literal, $C_name:ident, $C_type:ty,
695               [def:$C_def:stmt]
696            )* ;
697        copy@dep:
698            $( $C_doc_dep:literal, $C_name_dep:ident, $C_type_dep:ty,
699               $C_dep1_dep:literal, $C_dep2_dep:literal,
700               [def:$C_def_dep:stmt]
701            )* ;
702        copy@ptr:
703            $( $C_doc_ptr:literal, $C_name_ptr:ident, $C_type_ptr:ty,
704               $C_ptr_ptr:meta,
705               [def:$C_def_ptr:stmt]
706            )* ;
707        copy@ptrdep:
708            $( $C_doc_ptrdep:literal, $C_name_ptrdep:ident, $C_type_ptrdep:ty,
709               $C_ptr_ptrdep:meta, $C_dep1_ptrdep:literal, $C_dep2_ptrdep:literal,
710               [def:$C_def_ptrdep:stmt]
711            )* ;
712
713        noncopy:
714            $( $N_doc:literal, $N_name:ident, $N_type:ty,
715               [def:$N_def:stmt]
716            )* ;
717        noncopy@dep:
718            $( $N_doc_dep:literal, $N_name_dep:ident, $N_type_dep:ty,
719               $N_dep1_dep:literal, $N_dep2_dep:literal,
720               [def:$N_def_dep:stmt]
721            )* ;
722        noncopy@ptr:
723            $( $N_doc_ptr:literal, $N_name_ptr:ident, $N_type_ptr:ty,
724               $N_ptr_ptr:meta, $N_dep1_ptr:literal, $N_dep2_ptr:literal,
725               [def:$N_def_ptr:stmt]
726            )* ;
727        noncopy@ptrdep:
728            $( $N_doc_ptrdep:literal, $N_name_ptrdep:ident, $N_type_ptrdep:ty,
729               $N_ptr_ptrdep:meta,
730               $N_dep1_ptrdep:literal, $N_dep2_ptrdep:literal,
731               [def:$N_def_ptrdep:stmt]
732            )* ;
733    ) => { $crate::paste!{
734        // ## copy version (DataRaw)
735        // -----------------------------------------------------------------
736        #[repr(C)]
737        #[doc = $b "-bit *raw* data, restricted to `Copy` variants."]
738        #[derive(Copy, Clone)]
739        #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = $feature)))]
740        #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "unsafe_layout")))]
741        #[cfg(all(not(feature = "safe_data"), feature = "unsafe_layout"))]
742        #[allow(non_snake_case, reason = "union fields named like enum variants")]
743        pub union [< $Raw $b Copy >] {
744            /// Represents the absence of *data*.
745            pub None: (),
746
747            $(
748                #[doc = $C_doc]
749                pub $C_name: $C_type,
750            )*
751
752            $( // pointer-size dependant
753                #[cfg($C_ptr_ptr)]
754                #[doc = $C_doc_ptr]
755                $C_name_ptr: $C_type_ptr,
756            )*
757
758            // feature-gated dependencies
759            $(
760                #[cfg(all(feature = $C_dep1_dep, feature = $C_dep2_dep))]
761                #[cfg_attr(feature = "nightly_doc",
762                    doc(cfg(all(feature = $C_dep1_dep,
763                                feature = $C_dep2_dep))))]
764                #[doc = $C_doc_dep]
765                pub $C_name_dep: $C_type_dep,
766            )*
767
768            $( // pointer-size & feature-gated dependencies
769                #[cfg(all($C_ptr_ptrdep,
770                        feature = $C_dep1_ptrdep,
771                        feature = $C_dep2_ptrdep))]
772                #[cfg_attr(feature = "nightly_doc",
773                    doc(cfg(all(feature = $C_dep1_ptrdep,
774                                feature = $C_dep2_ptrdep))))]
775                #[doc = $C_doc_ptrdep]
776                $C_name_ptrdep($C_type_ptrdep),
777            )*
778        }
779        // type aliases:
780        // TODO
781        // #[doc = $b "-bit *untyped (raw)* data"]
782        // #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = $feature)))]
783        // pub type [< $Raw $b Copy >] = [< $Raw $b >];
784
785        // Debug
786        #[cfg(all(not(feature = "safe_data"), feature = "unsafe_layout"))]
787        impl core::fmt::Debug for [<$Raw $b Copy>] {
788            fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
789                write!(f, "{} {{...}}", stringify!{[< $Raw $b Copy>]})
790            }
791        }
792
793        #[cfg(all(not(feature = "safe_data"), feature = "unsafe_layout"))]
794        $crate::impl_data_raw![
795            r: [< $Raw $b Copy>],
796        ];
797    }};
798}
799#[allow(unused_imports)]
800pub(crate) use define_data_raw;