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
//! Defines `Relevant` type to use in types that requires //! custom dealocation. //! /// Values of this type can't be automatically dropped. /// If struct or enum has field with type `Relevant`, /// it can't be automatically dropped either. And so considered relevant too. /// User has to deconstruct such values and call `Relevant::dispose`. /// If relevant field is private it means that user has to move value into some public method. /// For example `memory::Block` should be returned to the `MemoryAllocator` it came from. /// /// User of the engine won't usually deal with real relevant types. /// More often user will face wrappers that has backdoor - some technique /// to dispose internal relevant fields with runtime cost. /// In debug mode such wrappers can put warnings in log. /// So that user will know they should be disposed manually. /// /// # Panics /// /// Panics when dropped. /// #[derive(Clone, Debug, PartialOrd, PartialEq, Ord, Eq, Hash)] pub struct Relevant; impl Relevant { /// Dispose this value. pub fn dispose(self) { ::std::mem::forget(self) } } impl Drop for Relevant { fn drop(&mut self) { println!("Values of this type can't be dropped!") } }