SHARE
TWEET

Untitled

a guest Jun 19th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #![feature(const_generics, const_fn)]
  2.  
  3. use std::default::Default;
  4.  
  5. pub struct Data<T, const N: usize>
  6. where
  7.     T: Sized + Default + Copy,
  8. {
  9.     data: [T; N],
  10. }
  11.  
  12. impl <T, const N: usize> Data<T, {N}> where T: Sized + Default + Copy {
  13.     pub fn new() -> Self {
  14.         Self {
  15.             data: [T::default(); N],
  16.         }
  17.     }
  18.  
  19.     pub const fn size(&self) -> usize {
  20.         {N}
  21.     }
  22. }
  23.  
  24.  
  25.  
  26. fn main() {
  27.     let data = Data::<u32, 20>::new();
  28.     println!("{}", data.size());
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top