Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(const_generics, const_fn)]
- use std::default::Default;
- pub struct Data<T, const N: usize>
- where
- T: Sized + Default + Copy,
- {
- data: [T; N],
- }
- impl <T, const N: usize> Data<T, {N}> where T: Sized + Default + Copy {
- pub fn new() -> Self {
- Self {
- data: [T::default(); N],
- }
- }
- pub const fn size(&self) -> usize {
- {N}
- }
- }
- fn main() {
- let data = Data::<u32, 20>::new();
- println!("{}", data.size());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement