Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/syn/src/drops.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / syn / src / drops.rs` 58 lines ยท 1414 bytes Raw Blame History 1 use core::iter; 2 use core::mem::ManuallyDrop; 3 use core::ops::{Deref, DerefMut}; 4 use core::option; 5 use core::slice; 6 7 #[repr(transparent)] 8 pub(crate) struct NoDrop(ManuallyDrop); 9 10 impl NoDrop { 11 pub(crate) fn new(value: T) -> Self 12 where 13 T: TrivialDrop, 14 { 15 NoDrop(ManuallyDrop::new(value)) 16 } 17 } 18 19 impl Deref for NoDrop { 20 type Target = T; 21 fn deref(&self) -> &Self::Target { 22 &self.0 23 } 24 } 25 26 impl DerefMut for NoDrop { 27 fn deref_mut(&mut self) -> &mut Self::Target { 28 &mut self.0 29 } 30 } 31 32 pub(crate) trait TrivialDrop {} 33 34 impl TrivialDrop for iter::Empty {} 35 impl TrivialDrop for slice::Iter<'_, T> {} 36 impl TrivialDrop for slice::IterMut<'_, T> {} 37 impl TrivialDrop for option::IntoIter<&T> {} 38 impl TrivialDrop for option::IntoIter<&mut T> {} 39 40 #[test] 41 fn test_needs_drop() { 42 use core::mem::needs_drop; 43 44 struct NeedsDrop; 45 46 impl Drop for NeedsDrop { 47 fn drop(&mut self) {} 48 } 49 50 assert!(needs_drop::()); 51 52 // Test each of the types with a handwritten TrivialDrop impl above. 53 assert!(!needs_drop::>()); 54 assert!(!needs_drop::>()); 55 assert!(!needs_drop::>()); 56 assert!(!needs_drop::>()); 57 assert!(!needs_drop::>()); 58 }