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/generic-array/src/impls.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 / generic-array / src / impls.rs` 269 lines ยท 6619 bytes Raw Blame History 1 use core::borrow::{Borrow, BorrowMut}; 2 use core::cmp::Ordering; 3 use core::fmt::{self, Debug}; 4 use core::hash::{Hash, Hasher}; 5 6 use super::{ArrayLength, GenericArray}; 7 8 use crate::functional::*; 9 use crate::sequence::*; 10 11 impl Default for GenericArray 12 where 13 N: ArrayLength, 14 { 15 #[inline(always)] 16 fn default() -> Self { 17 Self::generate(|_| T::default()) 18 } 19 } 20 21 impl Clone for GenericArray 22 where 23 N: ArrayLength, 24 { 25 fn clone(&self) -> GenericArray { 26 self.map(Clone::clone) 27 } 28 } 29 30 impl Copy for GenericArray 31 where 32 N: ArrayLength, 33 N::ArrayType: Copy, 34 { 35 } 36 37 impl PartialEq for GenericArray 38 where 39 N: ArrayLength, 40 { 41 fn eq(&self, other: &Self) -> bool { 42 **self == **other 43 } 44 } 45 impl Eq for GenericArray where N: ArrayLength {} 46 47 impl PartialOrd for GenericArray 48 where 49 N: ArrayLength, 50 { 51 fn partial_cmp(&self, other: &GenericArray) -> Option { 52 PartialOrd::partial_cmp(self.as_slice(), other.as_slice()) 53 } 54 } 55 56 impl Ord for GenericArray 57 where 58 N: ArrayLength, 59 { 60 fn cmp(&self, other: &GenericArray) -> Ordering { 61 Ord::cmp(self.as_slice(), other.as_slice()) 62 } 63 } 64 65 impl Debug for GenericArray 66 where 67 N: ArrayLength, 68 { 69 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { 70 self[..].fmt(fmt) 71 } 72 } 73 74 impl Borrow<[T]> for GenericArray 75 where 76 N: ArrayLength, 77 { 78 #[inline(always)] 79 fn borrow(&self) -> &[T] { 80 &self[..] 81 } 82 } 83 84 impl BorrowMut<[T]> for GenericArray 85 where 86 N: ArrayLength, 87 { 88 #[inline(always)] 89 fn borrow_mut(&mut self) -> &mut [T] { 90 &mut self[..] 91 } 92 } 93 94 impl AsRef<[T]> for GenericArray 95 where 96 N: ArrayLength, 97 { 98 #[inline(always)] 99 fn as_ref(&self) -> &[T] { 100 &self[..] 101 } 102 } 103 104 impl AsMut<[T]> for GenericArray 105 where 106 N: ArrayLength, 107 { 108 #[inline(always)] 109 fn as_mut(&mut self) -> &mut [T] { 110 &mut self[..] 111 } 112 } 113 114 impl Hash for GenericArray 115 where 116 N: ArrayLength, 117 { 118 fn hash(&self, state: &mut H) 119 where 120 H: Hasher, 121 { 122 Hash::hash(&self[..], state) 123 } 124 } 125 126 macro_rules! impl_from { 127 ($($n: expr => $ty: ty),*) => { 128 $( 129 impl From<[T; $n]> for GenericArray { 130 #[inline(always)] 131 fn from(arr: [T; $n]) -> Self { 132 unsafe { $crate::transmute(arr) } 133 } 134 } 135 136 #[cfg(relaxed_coherence)] 137 impl From> for [T; $n] { 138 #[inline(always)] 139 fn from(sel: GenericArray) -> [T; $n] { 140 unsafe { $crate::transmute(sel) } 141 } 142 } 143 144 impl<'a, T> From<&'a [T; $n]> for &'a GenericArray { 145 #[inline] 146 fn from(slice: &[T; $n]) -> &GenericArray { 147 unsafe { &*(slice.as_ptr() as *const GenericArray) } 148 } 149 } 150 151 impl<'a, T> From<&'a mut [T; $n]> for &'a mut GenericArray { 152 #[inline] 153 fn from(slice: &mut [T; $n]) -> &mut GenericArray { 154 unsafe { &mut *(slice.as_mut_ptr() as *mut GenericArray) } 155 } 156 } 157 158 #[cfg(not(relaxed_coherence))] 159 impl Into<[T; $n]> for GenericArray { 160 #[inline(always)] 161 fn into(self) -> [T; $n] { 162 unsafe { $crate::transmute(self) } 163 } 164 } 165 166 impl AsRef<[T; $n]> for GenericArray { 167 #[inline] 168 fn as_ref(&self) -> &[T; $n] { 169 unsafe { $crate::transmute(self) } 170 } 171 } 172 173 impl AsMut<[T; $n]> for GenericArray { 174 #[inline] 175 fn as_mut(&mut self) -> &mut [T; $n] { 176 unsafe { $crate::transmute(self) } 177 } 178 } 179 )* 180 } 181 } 182 183 impl_from! { 184 1 => ::typenum::U1, 185 2 => ::typenum::U2, 186 3 => ::typenum::U3, 187 4 => ::typenum::U4, 188 5 => ::typenum::U5, 189 6 => ::typenum::U6, 190 7 => ::typenum::U7, 191 8 => ::typenum::U8, 192 9 => ::typenum::U9, 193 10 => ::typenum::U10, 194 11 => ::typenum::U11, 195 12 => ::typenum::U12, 196 13 => ::typenum::U13, 197 14 => ::typenum::U14, 198 15 => ::typenum::U15, 199 16 => ::typenum::U16, 200 17 => ::typenum::U17, 201 18 => ::typenum::U18, 202 19 => ::typenum::U19, 203 20 => ::typenum::U20, 204 21 => ::typenum::U21, 205 22 => ::typenum::U22, 206 23 => ::typenum::U23, 207 24 => ::typenum::U24, 208 25 => ::typenum::U25, 209 26 => ::typenum::U26, 210 27 => ::typenum::U27, 211 28 => ::typenum::U28, 212 29 => ::typenum::U29, 213 30 => ::typenum::U30, 214 31 => ::typenum::U31, 215 32 => ::typenum::U32 216 } 217 218 #[cfg(feature = "more_lengths")] 219 impl_from! { 220 33 => ::typenum::U33, 221 34 => ::typenum::U34, 222 35 => ::typenum::U35, 223 36 => ::typenum::U36, 224 37 => ::typenum::U37, 225 38 => ::typenum::U38, 226 39 => ::typenum::U39, 227 40 => ::typenum::U40, 228 41 => ::typenum::U41, 229 42 => ::typenum::U42, 230 43 => ::typenum::U43, 231 44 => ::typenum::U44, 232 45 => ::typenum::U45, 233 46 => ::typenum::U46, 234 47 => ::typenum::U47, 235 48 => ::typenum::U48, 236 49 => ::typenum::U49, 237 50 => ::typenum::U50, 238 51 => ::typenum::U51, 239 52 => ::typenum::U52, 240 53 => ::typenum::U53, 241 54 => ::typenum::U54, 242 55 => ::typenum::U55, 243 56 => ::typenum::U56, 244 57 => ::typenum::U57, 245 58 => ::typenum::U58, 246 59 => ::typenum::U59, 247 60 => ::typenum::U60, 248 61 => ::typenum::U61, 249 62 => ::typenum::U62, 250 63 => ::typenum::U63, 251 64 => ::typenum::U64, 252 253 70 => ::typenum::U70, 254 80 => ::typenum::U80, 255 90 => ::typenum::U90, 256 257 100 => ::typenum::U100, 258 200 => ::typenum::U200, 259 300 => ::typenum::U300, 260 400 => ::typenum::U400, 261 500 => ::typenum::U500, 262 263 128 => ::typenum::U128, 264 256 => ::typenum::U256, 265 512 => ::typenum::U512, 266 267 1000 => ::typenum::U1000, 268 1024 => ::typenum::U1024 269 }