1 #![cfg_attr(feature = "used_linker", feature(used_with_arg))] 2 3 use linkme::distributed_slice; 4 use once_cell::sync::Lazy; 5 6 #[distributed_slice] 7 static SHENANIGANS: [i32] = [..]; 8 9 #[distributed_slice(SHENANIGANS)] 10 static N: i32 = 9; 11 12 #[distributed_slice(SHENANIGANS)] 13 static NN: i32 = 99; 14 15 #[distributed_slice(SHENANIGANS)] 16 static NNN: i32 = 999; 17 18 #[test] test()19fn test() { 20 assert_eq!(SHENANIGANS.len(), 3); 21 22 let mut sum = 0; 23 for n in SHENANIGANS { 24 sum += n; 25 } 26 27 assert_eq!(sum, 9 + 99 + 999); 28 } 29 30 #[test] test_empty()31fn test_empty() { 32 #[distributed_slice] 33 static EMPTY: [i32] = [..]; 34 35 assert!(EMPTY.is_empty()); 36 } 37 38 #[test] test_non_copy()39fn test_non_copy() { 40 struct NonCopy(i32); 41 42 #[distributed_slice] 43 static NONCOPY: [NonCopy] = [..]; 44 45 #[distributed_slice(NONCOPY)] 46 static ELEMENT: NonCopy = NonCopy(9); 47 48 assert!(!NONCOPY.is_empty()); 49 } 50 51 #[test] test_interior_mutable()52fn test_interior_mutable() { 53 #[distributed_slice] 54 static MUTABLE: [Lazy<i32>] = [..]; 55 56 #[distributed_slice(MUTABLE)] 57 static ELEMENT: Lazy<i32> = Lazy::new(|| -1); 58 59 assert!(MUTABLE.len() == 1); 60 assert!(*MUTABLE[0] == -1); 61 } 62 63 #[test] test_elided_lifetime()64fn test_elided_lifetime() { 65 #[distributed_slice] 66 pub static MYSLICE: [&str] = [..]; 67 68 #[distributed_slice(MYSLICE)] 69 static ELEMENT: &str = "..."; 70 71 assert!(!MYSLICE.is_empty()); 72 } 73