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
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
/// Conditional code generation in case
/// the structure is safe or unsafe
#[doc(hidden)]
#[macro_export]
macro_rules! __if_codegen {
[
if ( #true ) {
$($all:tt)*
} $(else {
$($else:tt)*
})?
] => {
$( $all )?
};
[
if ( #false ) {
$($all:tt)*
} $(else {
$($else:tt)*
})?
] => {
$( $($else)* )?
};
($($all:tt)*) => {
compile_error!(
concat!(
"Please check the spelling of the macro, body: '",
stringify!($($all)*),
"'"
)
);
}
}
/// Conditional code generation if standard library compatibility
/// is enabled and whether the framework is safe or unsafe.
#[doc(hidden)]
#[macro_export]
#[cfg(feature = "always_compatible_stdapi")]
macro_rules! __codegen_compatible_stdapi_ornot {
(
#if_compatible_stdapi_and_safeapi (#is_always_compatible: true || ( #is_feature && #is_maybe_compatible: $_is_maybe_compatible:tt)) {
$($true_code:tt)*
} $(else { $( $false_code:tt)* })?
) => {
$($true_code)* // <-- TRUE
};
(
#if_compatible_stdapi_and_safeapi (#is_always_compatible: $_is_always_compatible:tt || ( #is_feature && #is_maybe_compatible: true)) {
$($true_code:tt)*
} $(else { $( $false_code:tt)* })?
) => {
$($true_code)* // <-- TRUE
};
(
#if_compatible_stdapi_and_safeapi (#is_always_compatible: $_is_always_compatible:tt || ( #is_feature && #is_maybe_compatible: false)) {
$($true_code:tt)*
} $(else { $( $false_code:tt)* })?
) => {
$( $($false_code)* )? // <-- FALSE
};
($($all:tt)*) => {
compile_error!(
concat!(
"Please check the spelling of the macro, body: '",
stringify!($($all)*),
"'"
)
);
}
}
/// Conditional code generation if standard library compatibility
/// is enabled and whether the framework is safe or unsafe.
#[doc(hidden)]
#[macro_export]
#[cfg(not(feature = "always_compatible_stdapi"))]
macro_rules! __codegen_compatible_stdapi_ornot {
(
#if_compatible_stdapi_and_safeapi (#is_always_compatible: true || ( #is_feature && #is_maybe_compatible: $_is_maybe_compatible:tt)) {
$($true_code:tt)*
} $(else { $( $false_code:tt)* })?
) => {
$($true_code)* // <-- TRUE
};
(
#if_compatible_stdapi_and_safeapi (#is_always_compatible: $_is_always_compatible:tt || ( #is_feature && #is_maybe_compatible: true)) {
$($true_code:tt)*
} $(else { $( $false_code:tt)* })?
) => {
$( $($false_code)* )? // <-- FALSE
};
(
#if_compatible_stdapi_and_safeapi (#is_always_compatible: $_is_always_compatible:tt || ( #is_feature && #is_maybe_compatible: false)) {
$($true_code:tt)*
} $(else { $( $false_code:tt)* })?
) => {
$( $($false_code)* )? // <-- FALSE
};
($($all:tt)*) => {
compile_error!(
concat!(
"Please check the spelling of the macro, body: '",
stringify!($($all)*),
"'"
)
);
}
}
/// Internal code generation is needed more for compatibility
/// and bypassing trait restrictions.
#[doc(hidden)]
#[macro_export]
macro_rules! __codegen {
[
@use;
$(
$($all:tt)+
)?
] => {
use crate::core::state::StateManuallyDropData;
#[allow(unused_imports)]
use crate::core::state::StateManuallyDrop;
use ::core::ops::DerefMut;
use ::core::ops::Deref;
use ::core::fmt::Debug;
use ::core::hash::Hash;
#[allow(unused_imports)]
use crate::core::state::EMPTY_STATE;
$(
$crate::__codegen! {
$($all)+
}
)?
};
[
@impl $current_type: tt {
is_safe: $is_safe: tt,
is_always_compatible: $is_always_compatible: tt,
is_maybe_compatible: $is_maybe_compatible: tt,
is_repr_transparent: $is_repr_transparent: tt,
fn {
$(#[$($__tt:tt)*])? // ignore comments
new |$new_value_fn:ident| $new_fn: block
$(#[$($___tt:tt)*])? // ignore comments
as_unsafestd_manuallydrop |$sself_as_unsafestd_manuallydrop: ident| $as_unsafestd_manuallydrop: block
$(#[$($____tt:tt)*])? // ignore comments
as_mut_unsafestd_manuallydrop |$sself_as_mut_unsafestd_manuallydrop: ident| $as_mut_unsafestd_manuallydrop: block
$(#[$($_____tt:tt)*])? // ignore comments
force_as_value |$sself_force_as_value: ident| $force_as_value_fn: block
$(#[$($______tt:tt)*])? // ignore comments
force_as_mut_value |$sself_force_as_mut_value: ident| $force_as_mut_value_fn: block
}
}
$(
$($all:tt)+
)?
] => {
impl<T, Trig> $current_type<T, Trig> where Trig: TrigManuallyDrop {
/// Wrap a value to be manually dropped.
#[inline]
pub const fn new(value: T) -> Self {
let value = UnsafeStdManuallyDrop::new(value);
unsafe {
Self::from_std(value)
}
}
/// Wrap a value to be manually dropped.
/// Unsafe because the UnsafeStdManuallyDrop input argument is in an undefined state.
#[inline]
pub const unsafe fn from_std($new_value_fn: UnsafeStdManuallyDrop<T>) -> Self {
$new_fn
}
/// Forgets value (similar to core::mem::forget), if you need to forget a
/// value in ManuallyData use ignore_drop() instead of this function.
#[inline(always)]
pub fn forget(value: T) {
let sself = Self::new(value);
#[allow(unused_unsafe)]
unsafe {
sself.ignore_drop();
}
}
$crate::__if_codegen! {
if (#$is_safe) {
/// Extracts the value from the ManuallyDrop container.
#[inline]
pub /*const*/ fn into_inner(slot: $current_type<T, Trig>) -> T {
slot.state.to_intoinnermode_or_trig::<Trig>();
// into_inner
let mut slot = slot;
let value: T = unsafe {
UnsafeStdManuallyDrop::take(
slot.as_mut_unsafestd_manuallydrop()
)
};
let _ignore_drop = UnsafeStdManuallyDrop::new(slot);
value
}
/// Extracts the value from the ManuallyDrop container.
#[inline]
pub /*const*/ fn into_core_inner(slot: $current_type<T, Trig>) -> UnsafeStdManuallyDrop<T> {
slot.state.to_intoinnermode_or_trig::<Trig>();
// analog UnsafeManuallyDrop::take
let mandrop: UnsafeStdManuallyDrop<T> = unsafe {
::core::ptr::read(slot.as_unsafestd_manuallydrop())
};
let _ignore_drop = UnsafeStdManuallyDrop::new(slot);
mandrop
}
}else {
/// Extracts the value from the ManuallyDrop container.
/// !!!(The unsafe version of the function is identical to the UnsafeStdManuallyDrop::into_inner core.)
#[inline]
pub const fn into_inner(slot: $current_type<T, Trig>) -> T {
UnsafeStdManuallyDrop::into_inner($current_type::into_core_inner(slot))
}
/// Extracts the value from the ManuallyDrop container.
/// !!!(The unsafe version of the function is identical to the UnsafeStdManuallyDrop::into_inner core.)
#[inline]
pub const fn into_core_inner(slot: $current_type<T, Trig>) -> UnsafeStdManuallyDrop<T> {
slot.value
}
}
}
// TODO! duplication of code, it could have been solved if the rust would allow
// it to be done somehow differently, but at this stage it’s the only way.
$crate::__codegen_compatible_stdapi_ornot! {
#if_compatible_stdapi_and_safeapi (#is_always_compatible: $is_always_compatible || ( #is_feature && #is_maybe_compatible: $is_maybe_compatible)) {
/// Takes the value from the ManuallyDrop<T> container out.
#[inline(always)]
pub unsafe fn take(slot: &mut $current_type<T, Trig>) -> T {
$crate::__if_codegen! {
if (#$is_safe) {
slot.state.to_takemode_or_trig::<Trig>();
}
}
#[allow(unused_unsafe)]
unsafe { // library provides security guarantees
UnsafeStdManuallyDrop::take(&mut slot.value)
}
}
} else {
/// Takes the value from the ManuallyDrop<T> container out.
#[inline(always)]
pub fn take(slot: &mut $current_type<T, Trig>) -> T {
$crate::__if_codegen! {
if (#$is_safe) {
slot.state.to_takemode_or_trig::<Trig>();
}
}
unsafe { // library provides security guarantees
UnsafeStdManuallyDrop::take(&mut slot.value)
}
}
}
}
}
impl<T, Trig> $current_type<T, Trig> where T: ?Sized, Trig: TrigManuallyDrop {
// TODO! duplication of code, it could have been solved if the rust would allow
// it to be done somehow differently, but at this stage it’s the only way.
$crate::__codegen_compatible_stdapi_ornot! {
#if_compatible_stdapi_and_safeapi (#is_always_compatible: $is_always_compatible || ( #is_feature && #is_maybe_compatible: $is_maybe_compatible)) {
/// Get reference to value.
#[inline(always)]
pub unsafe fn as_value(&self) -> &T {
$crate::__if_codegen! {
if (#$is_safe) {
self.state.deref_or_trig::<Trig>();
}
}
self.force_as_value()
}
/// Get a mutable reference to a value.
#[inline(always)]
pub unsafe fn as_mut_value(&mut self) -> &mut T {
$crate::__if_codegen! {
if (#$is_safe) {
self.state.deref_or_trig::<Trig>();
}
}
self.force_as_mut_value()
}
/// PSEUDO SAFE! In safe ManuallyDrop, this function prevents undefined behavior at run time,
/// but the resulting raw pointer is not protected and does not depend on lifetime
/// and may be dangling.
#[inline(always)]
pub unsafe fn as_ptr(&self) -> *const T {
// TODO, VALID?, Exp: ManuallyDrop::as_ptr
self.as_value() as _
}
/// PSEUDO SAFE! In safe ManuallyDrop, this function prevents undefined behavior at run time,
/// but the resulting raw pointer is not protected and does not depend on lifetime
/// and may be dangling.
#[inline(always)]
pub unsafe fn as_mut_ptr(&mut self) -> *mut T {
// TODO, VALID?, Exp: ManuallyDrop::as_mut_ptr
self.as_mut_value() as _
}
/// Manually drops the contained value.
#[inline(always)]
pub unsafe fn drop(slot: &mut $current_type<T, Trig>) {
$crate::__if_codegen! {
if (#$is_safe) {
slot.state.to_dropmode_or_trig::<Trig>();
}
}
UnsafeStdManuallyDrop::drop(&mut slot.value)
}
$crate::__if_codegen! {
if (#$is_safe) {
/// Note that the safe ManuallyDrop checks to see if the value is freed when the safe ManuallyDrop struct dies.
/// The version of mem::forget is adapted for safe and insecure ManuallyDrop.
#[inline(always)]
pub unsafe fn ignore_drop(&self) {
self.state.to_ignore_trig_when_drop::<Trig>();
}
} else {
/// Note that the safe ManuallyDrop checks to see if the value is freed when the safe ManuallyDrop struct dies.
/// The version of mem::forget is adapted for safe and insecure ManuallyDrop.
/// !!!(Not supported in insecure version, does nothing).
#[inline(always)]
pub const unsafe fn ignore_drop(&self) {}
}
}
} else {
/// Get reference to value.
#[inline(always)]
pub fn as_value(&self) -> &T {
$crate::__if_codegen! {
if (#$is_safe) {
self.state.deref_or_trig::<Trig>();
}
}
unsafe {
self.force_as_value()
}
}
/// Get a mutable reference to a value.
#[inline(always)]
pub fn as_mut_value(&mut self) -> &mut T {
$crate::__if_codegen! {
if (#$is_safe) {
self.state.deref_or_trig::<Trig>();
}
}
unsafe {
self.force_as_mut_value()
}
}
/// PSEUDO SAFE! In safe ManuallyDrop, this function prevents undefined behavior at run time,
/// but the resulting raw pointer is not protected and does not depend on lifetime
/// and may be dangling.
#[inline(always)]
pub fn as_ptr(&self) -> *const T {
// TODO, VALID?, Exp: ManuallyDrop::as_ptr
self.as_value() as _
}
/// PSEUDO SAFE! In safe ManuallyDrop, this function prevents undefined behavior at run time,
/// but the resulting raw pointer is not protected and does not depend on lifetime
/// and may be dangling.
#[inline(always)]
pub fn as_mut_ptr(&mut self) -> *mut T {
// TODO, VALID?, Exp: ManuallyDrop::as_mut_ptr
self.as_mut_value() as _
}
/// Manually drops the contained value.
#[inline(always)]
pub fn drop(slot: &mut $current_type<T, Trig>) {
$crate::__if_codegen! {
if (#$is_safe) {
slot.state.to_dropmode_or_trig::<Trig>();
}
}
unsafe { // library provides security guarantees
UnsafeStdManuallyDrop::drop(&mut slot.value)
}
}
$crate::__if_codegen! {
if (#$is_safe) {
/// Note that the safe ManuallyDrop checks to see if the value is freed when the safe ManuallyDrop struct dies.
/// The version of mem::forget is adapted for safe and insecure ManuallyDrop.
#[inline(always)]
pub fn ignore_drop(&self) {
self.state.to_ignore_trig_when_drop::<Trig>();
}
} else {
/// Note that the safe ManuallyDrop checks to see if the value is freed when the safe ManuallyDrop struct dies.
/// The version of mem::forget is adapted for safe and insecure ManuallyDrop.
/// !!!(Not supported in insecure version, does nothing).
#[inline(always)]
pub const fn ignore_drop(&self) {}
}
}
}
}
#[inline(always)]
pub const unsafe fn as_unsafestd_manuallydrop(&self) -> &UnsafeStdManuallyDrop<T> {
let $sself_as_unsafestd_manuallydrop = self;
$as_unsafestd_manuallydrop
}
#[inline(always)]
pub unsafe fn as_mut_unsafestd_manuallydrop(&mut self) -> &mut UnsafeStdManuallyDrop<T> {
let $sself_as_mut_unsafestd_manuallydrop = self;
$as_mut_unsafestd_manuallydrop
}
/// Is ManuallyDrop a wrapper with values, or is it actually a transparent
/// value with no false data.
#[inline(always)]
pub const fn is_repr_transparent(&self) -> bool {
$is_repr_transparent
}
$crate::__if_codegen! {
if (#$is_safe) {
/// Get current state
#[inline]
pub /*const*/ fn get_state(&self) -> Option<StateManuallyDropData> {
// Safe
Some(self.state.read())
}
/// Checking if a trigger that defines undefined behavior will fire.
/// Some(true) - means that the state is empty and you can work with the value later.
/// Some(false) means that the value has already been converted by some method, and
/// further work with the value will cause an undefined behavior trigger.
/// None - This version of ManuallyDrop is stateless, so defining undefined behavior
/// is not possible.
#[inline]
pub fn is_empty_state(&self) -> Option<bool> {
// Safe
Some(self.state.is_empty())
}
/// Resets the ManuallyDrop state to its original state and returns the previous state.
#[inline]
pub unsafe fn get_state_and_reset(&self) -> Option<StateManuallyDropData> {
// Safe
Some(self.state.get_and_reset())
}
/// Checking if a trigger that defines undefined behavior will fire.
/// false - means the state is empty and you can work with the value in the future.
/// - true means the value has already been converted by some method.
#[inline]
pub fn is_next_trig(&self) -> bool {
self.state.is_next_trig()
}
/// Checking if a trigger that defines undefined behavior will fire.
/// Some(false) - means that the state is empty and you can work with the value later.
/// Some(true) means that the value has already been converted by some method, and further work with the value will cause an undefined behavior trigger.
/// None - This version of ManuallyDrop is stateless, so defining undefined behavior is not possible.
#[inline]
pub fn is_next_trig_optionresult(&self) -> Option<bool> {
Some(self.state.is_next_trig())
}
} else {
/// Get current state
/// !!!(Not supported in the unsafe version, always returns None).
#[inline(always)]
pub const fn get_state(&self) -> Option<StateManuallyDropData> {
None
}
/// Checking if a trigger that defines undefined behavior will fire.
/// Some(true) - means that the state is empty and you can work with the value later.
/// Some(false) means that the value has already been converted by some method, and
/// further work with the value will cause an undefined behavior trigger.
/// None - This version of ManuallyDrop is stateless, so defining undefined behavior
/// is not possible.
/// !!!(Not supported in the unsafe version, always returns None).
#[inline]
pub const fn is_empty_state(&self) -> Option<bool> {
None
}
/// Resets the ManuallyDrop state to its original state and returns the previous state.
/// !!!(Not supported in the unsafe version, always returns None).
#[inline(always)]
pub const unsafe fn get_state_and_reset(&self) -> Option<StateManuallyDropData> {
None
}
/// Checking if a trigger that defines undefined behavior will fire.
/// false - means the state is empty and you can work with the value in the future.
/// - true means the value has already been converted by some method.
/// !!!(Not supported in the unsafe version, always returns false).
#[inline(always)]
pub const fn is_next_trig(&self) -> bool {
false
}
/// Checking if a trigger that defines undefined behavior will fire.
/// Some(false) - means that the state is empty and you can work with the value later.
/// Some(true) means that the value has already been converted by some method, and further work with the value will cause an undefined behavior trigger.
/// None - This version of ManuallyDrop is stateless, so defining undefined behavior is not possible.
/// !!!(Not supported in the unsafe version, always returns None).
#[inline(always)]
pub const fn is_next_trig_optionresult(&self) -> Option<bool> {
None
}
}
}
/// Get a raw pointer to a value. The call is always insecure.
#[inline(always)]
pub /*const*/ unsafe fn force_as_ptr(&self) -> *const T {
// TODO, VALID?, Exp: ManuallyDrop::as_ptr
self.force_as_value() as _
}
/// Get a raw mut pointer to a value. The call is always insecure.
#[inline(always)]
pub /*const*/ unsafe fn force_as_mut_ptr(&mut self) -> *mut T {
// TODO, VALID?, Exp: ManuallyDrop::as_mut_ptr
self.force_as_mut_value() as _
}
/// Get reference to value. Always unprotected!
#[inline(always)]
pub /*const*/ unsafe fn force_as_value(&self) -> &T {
let $sself_force_as_value = self;
$force_as_value_fn
}
/// Get a mutable reference to a value. Always unprotected!
#[inline(always)]
pub /*const*/ unsafe fn force_as_mut_value(&mut self) -> &mut T {
let $sself_force_as_mut_value = self;
$force_as_mut_value_fn
}
/// Safe or insecure version of ManuallyDrop.
#[inline(always)]
pub const fn is_safe_type(&self) -> bool {
$is_safe
}
}
// #[derive(/*Copy, */Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]:
//
impl<T, Trig> Clone for $current_type<T, Trig> where T: Sized + Clone, Trig: TrigManuallyDrop {
#[inline(always)]
fn clone(&self) -> Self {
let ref_value: &T = self.deref();
let value = Clone::clone(ref_value);
Self::new(value)
}
}
impl<T, Trig> Deref for $current_type<T, Trig> where T: ?Sized, Trig: TrigManuallyDrop {
type Target = T;
#[inline(always)]
fn deref(&self) -> &T {
#[allow(unused_unsafe)]
unsafe {
self.as_value()
}
}
}
impl<T, Trig> DerefMut for $current_type<T, Trig> where T: ?Sized, Trig: TrigManuallyDrop {
#[inline(always)]
fn deref_mut(&mut self) -> &mut T {
#[allow(unused_unsafe)]
unsafe {
self.as_mut_value()
}
}
}
impl<T, Trig> Default for $current_type<T, Trig> where T: Sized + Default, Trig: TrigManuallyDrop {
#[inline(always)]
fn default() -> Self {
let value: T = Default::default();
Self::new(value)
}
}
impl<T, Trig> PartialEq<Self> for $current_type<T, Trig> where T: PartialEq<T>, Trig: TrigManuallyDrop {
#[inline]
fn eq(&self, a: &Self) -> bool {
let value: &T = self.deref();
PartialEq::eq(value, a)
}
#[inline]
fn ne(&self, a: &Self) -> bool {
let value: &T = self.deref();
PartialEq::ne(value, a)
}
}
impl<T, Trig> PartialEq<T> for $current_type<T, Trig> where T: PartialEq<T>, Trig: TrigManuallyDrop {
#[inline]
fn eq(&self, a: &T) -> bool {
let value: &T = self.deref();
PartialEq::eq(value, a)
}
#[inline]
fn ne(&self, a: &T) -> bool {
let value: &T = self.deref();
PartialEq::ne(value, a)
}
}
impl<T, Trig> PartialEq<UnsafeStdManuallyDrop<T>> for $current_type<T, Trig> where T: PartialEq<T>, Trig: TrigManuallyDrop {
#[inline]
fn eq(&self, a: &UnsafeStdManuallyDrop<T>) -> bool {
let value: &T = self.deref();
PartialEq::eq(value, a)
}
#[inline]
fn ne(&self, a: &UnsafeStdManuallyDrop<T>) -> bool {
let value: &T = self.deref();
PartialEq::ne(value, a)
}
}
impl<T, Trig> Eq for $current_type<T, Trig> where T: Eq + PartialEq<T>, Trig: TrigManuallyDrop {
#[inline]
fn assert_receiver_is_total_eq(&self) {
let value: &T = self.deref();
Eq::assert_receiver_is_total_eq(value)
}
}
impl<T, Trig> Ord for $current_type<T, Trig> where T: Eq + PartialOrd<T> + Ord, Trig: TrigManuallyDrop {
#[inline]
fn cmp(&self, a: &Self) -> core::cmp::Ordering {
let value: &T = self.deref();
Ord::cmp(value, a)
}
}
impl<T, Trig> PartialOrd<Self> for $current_type<T, Trig> where T: PartialEq<T> + PartialOrd<T>, Trig: TrigManuallyDrop {
#[inline]
fn partial_cmp(&self, a: &Self) -> Option<core::cmp::Ordering> {
let value: &T = self.deref();
PartialOrd::partial_cmp(value, a)
}
}
impl<T, Trig> PartialOrd<T> for $current_type<T, Trig> where T: PartialEq<T> + PartialOrd<T>, Trig: TrigManuallyDrop {
#[inline]
fn partial_cmp(&self, a: &T) -> Option<core::cmp::Ordering> {
let value: &T = self.deref();
PartialOrd::partial_cmp(value, a)
}
}
impl<T, Trig> PartialOrd<UnsafeStdManuallyDrop<T>> for $current_type<T, Trig> where T: PartialEq<T> + PartialOrd<T>, Trig: TrigManuallyDrop {
#[inline]
fn partial_cmp(&self, a: &UnsafeStdManuallyDrop<T>) -> Option<core::cmp::Ordering> {
let value: &T = self.deref();
PartialOrd::partial_cmp(value, a)
}
}
impl<T, Trig> Hash for $current_type<T, Trig> where T: Hash, Trig: TrigManuallyDrop {
#[inline]
fn hash<H>(&self, a: &mut H) where H: core::hash::Hasher {
let value: &T = self.deref();
Hash::hash(value, a)
}
}
impl<T, Trig> Debug for $current_type<T, Trig> where T: Debug, Trig: TrigManuallyDrop {
#[inline(always)]
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> {
let value: &T = self.deref();
Debug::fmt(value, f)
}
}
impl<T, Trig> From<T> for $current_type<T, Trig> where T: Sized, Trig: TrigManuallyDrop {
#[inline(always)]
fn from(a: T) -> Self {
Self::new(a)
}
}
$(
$crate::__codegen! {
$($all)+
}
)?
};
($($all:tt)*) => {
compile_error!(
concat!(
"Please check the spelling of the macro, body: '",
stringify!($($all)*),
"'"
)
);
}
}