pub trait Resource {
// Required methods
unsafe fn clone_state(&self) -> Self;
unsafe fn set_cleanup_enabled(&mut self, cleanup_enabled: bool);
}Expand description
A resource is a type that can be moved inside or outside of a guard.
Required Methods§
Sourceunsafe fn clone_state(&self) -> Self
unsafe fn clone_state(&self) -> Self
Clone the resource state. The function is unsafe, because only one instance of the resource state should exist at a time. If there are multiple instances of the resource state, we need to make sure that their states are synchronized. If one instance is dropped and cleans up the resource, the other instances should become invalid.
Sourceunsafe fn set_cleanup_enabled(&mut self, cleanup_enabled: bool)
unsafe fn set_cleanup_enabled(&mut self, cleanup_enabled: bool)
Set weather the resource should be cleaned up when it is dropped. If have multiple states of the same resource, we need to make sure that only one of them is set to clean up the resource.
This method is unsafe, because it is possible to disable the cleanup of a resource, which brings the resource into an invalid state.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.