Derive Macro shredder::Scan [−][src]
#[derive(Scan)] { // Attributes available to this derive: #[shredder] }
Expand description
The Scan
derive, powering #[derive(Scan)]
. Important details here!
Doing #[derive(Scan)]
will in fact derive Scan
. However, it actually can auto-implement
four traits:
Scan
(automatic) [requires all fields beScan
]GcSafe
(automatic) [requires all fields beGcSafe
]GcDrop
(opt-out) [requires all fields beGcDrop
]GcDeref
(opt-in) [requires all fields beGcDeref
]
Scan
and GcSafe
are the fundamental things that this derive implements. There is no way
to opt out.
To opt out of GcDrop
, supply the cant_drop
flag. Ex:
use shredder::DerefGc; use shredder::Scan; #[derive(Scan)] #[shredder(cant_drop)] struct WontBeDrop { v: DerefGc<u32> }
To opt into GcDeref
, supply the can_deref
flag:
use shredder::DerefGc; use shredder::Scan; #[derive(Scan)] #[shredder(can_deref, cant_drop)] struct WillBeDeref { v: DerefGc<u32> }
Now there are also field flags, which will remove the recursive checks for that trait:
skip_scan
(skips check forScan
)unsafe_skip_gc_deref
(skips check forGcDeref
. Unsafe!)unsafe_skip_gc_drop
(skips check forGcDrop
. Unsafe!)unsafe_skip_gc_safe
(skips check forGcSafe
. Unsafe!)unsafe_skip_all
(skips check for all traits. Unsafe!)
For safety, if you use unsafe flags, you must ensure those fields satisfy the trait requirements anyway.
Here is an example of skip usage
use shredder::DerefGc; use shredder::Scan; #[derive(Scan)] struct WillBeDeref { #[shredder(skip_scan, unsafe_skip_gc_safe, unsafe_skip_gc_drop)] v: *const u32 // Assume this is always a valid ptr }