Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 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. Values3 = 3,
  9. Values4 = 4,
  10. Values6 = 6
  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. #[repr(transparent)]
  24. pub struct MyArray<T, const COUNT: ArrayCount>([ArrayItem<T>; COUNT as usize]);
  25.  
  26. impl<T> MyArray<T, {ArrayCount::Values3}> {
  27. pub(crate) const fn new() -> Self {
  28. Self([
  29. ArrayItem::new(),
  30. ArrayItem::new(),
  31. ArrayItem::new(),
  32. ])
  33. }
  34. }
  35.  
  36. fn main() {
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement