SafeManuallyDrop
A safe version of ManuallyDrop with various features and options to track undefined behavior when working with ManuallyDrop.
Use
1. easy
use ManuallyDrop;
use Deref;
2. hook
use Deref;
// For better performance, we recommend using AutoSafeHookManuallyDrop instead
// of AlwaysSafeHookManuallyDrop. The AutoSafeHookManuallyDrop type depends on
// the type of build, debug or release will be with the safe or insecure version
// of ManuallyDrop.
use AlwaysSafeHookManuallyDrop as ManuallyDrop;
3. counter
// Let me remind you that CounterManuallyDrop by behavior allows undefined
// behavior in the same way as ManuallyDrop, but, unlike ManuallyDrop,
// Counter keeps a counter of the number of undefined behavior triggers.
// !!!!
// CounterManuallyDrop is experimental and changes the behavior of
// the trigger trait for all types.
use AutoSafeCounterManuallyDrop as ManuallyDrop;
use ManuallyDrop;
use Deref;
cargo.toml -> features
// The ManuallyDrop type is always SafeManuallyDrop if the debug_assertions flag
// is active (test build, debug build).
"always_check_in_case_debug_assertions"
// The AutoSafeManuallyDrop/ManuallyDrop type is always SafeManuallyDrop,
// i.e. with traceable behavior.
#"always_safe_manuallydrop"
// For compatibility with older software, create a separate crate::core::hook
// instead of the new crate::core::trig::hook.
"enable_deprecated_hook"
// Mark functions as unsafe even if they are safe
// for std API compatibility.
"always_compatible_stdapi"
// Ability to determine if an empty loop trigger has been executed.
"support_istrig_loop"
// Support for PanicManuallyDrop, in case of undefined behavior
// of PanicManuallyDrop there will be a panic.
"support_panic_trig"
// HookManuallyDrop support, in case of undefined HookManuallyDrop behavior,
// the hook function will be called.
"support_hookfn_trig"
// Support for CounterManuallyDrop, in case of undefined behavior,
// CounterManuallyDrop will add +1 to the counter.
#"support_count_trig"
// The behavior for the simple AutoSafeManuallyDrop/AlwaysSafeManuallyDrop/ManuallyDrop type will always
// cause a panic in case of undefined behavior.
#"always_deftrig_panic"
// The behavior for the simple AutoSafeManuallyDrop/AlwaysSafeManuallyDrop/ManuallyDrop type will always
// call the hook function in case of undefined behavior.
#"always_deftrig_hookfn"
// The behavior for the simple AutoSafeManuallyDrop/AlwaysSafeManuallyDrop/ManuallyDrop type will always call
// the +1 counter function in case of undefined behavior.
#"always_deftrig_count"
// The behavior for the simple type AutoSafeManuallyDrop/AlwaysSafeManuallyDrop/ManuallyDrop will always call
// the eternal loop function in case of undefined behavior.
#"always_deftrig_loop"
// INFO:
// If the behavior for the general AutoSafeManuallyDrop/AlwaysSafeManuallyDrop/ManuallyDrop is not fixed,
// the behavior will be determined according to the following scheme:
//
// always_deftrig_panic not exists AND
// always_deftrig_hookfn not exists AND
// always_deftrig_count not exists AND
// always_deftrig_loop not exists THEN
//
// support_hookfn_trig -> Hook, else:
// support_panic_trig -> Panic, else:
// support_count_trig -> Count, else:
// Loop
//
License
Copyright 2022 #UlinProject Denis Kotlyarov (Денис Котляров)
Licensed under the Apache License, Version 2.0