Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #![feature(const_generics)]
  2.  
  3. use core::ptr::null_mut;
  4.  
  5. #[derive(Clone, Copy, Debug)]
  6. #[repr(usize)]
  7. pub enum ArrayCount {
  8. Values8 = 8,
  9. Values16 = 16,
  10. Values32 = 32
  11. }
  12.  
  13. /// Non-Copy type!
  14. #[repr(transparent)]
  15. struct ArrayItem<T>(*mut T);
  16.  
  17. impl<T> ArrayItem<T> {
  18. pub fn new() -> Self {
  19. Self(null_mut())
  20. }
  21. }
  22.  
  23.  
  24.  
  25. #[repr(transparent)]
  26. pub struct MyArray<T, const COUNT: ArrayCount>([ArrayItem<T>; COUNT as usize]);
  27.  
  28. impl<T> MyArray<T, {ArrayCount::Values8}> {
  29. pub(crate) const fn new() -> Self {
  30. Self([
  31. ArrayItem::new(),
  32. ArrayItem::new(),
  33. ArrayItem::new(),
  34. ArrayItem::new(),
  35. ArrayItem::new(),
  36. ArrayItem::new(),
  37. ArrayItem::new(),
  38. ArrayItem::new(),
  39. ])
  40. }
  41. }
  42.  
  43. fn main() {
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement