use std::mem;
use std::mem::MaybeUninit;
-type S = &'static str;
+pub fn default<T: Default>() -> T { Default::default() }
-
-#[repr(C)]
-struct Concat<const A: usize, const B: usize>(
- [S; A],
- [S; B],
-);
-
-trait Ish {
- const N: usize;
-}
-
-trait Has<const N: usize> {
- const F: [S; N];
-}
-
-struct Inner { i: usize, }
-
-impl Ish for Inner {
- const N: usize = 1;
-}
-impl Has<1> for Inner {
- const F: [S; 1] = ["i"];
+#[derive(Debug)]
+struct AutoStackVec<const N: usize, T> {
+ used: usize,
+ buf: [T; N],
}
-struct Outer { o: usize, p: usize }
-
-impl Ish for Outer {
- const N: usize = Inner::N + 2;
-}
-impl Has<{ Inner::N + 2 }> for Outer {
- const F: [S; Inner::N + 2] = {
- const TUPLE: Concat<
- 2,
- { Inner::N },
- > = Concat(
- ["o", "p"],
- Inner::F,
- );
- unsafe { mem::transmute(TUPLE) }
- };
-}
-
-/*
-const fn plus<const N: usize>
-(x: &'static [S],
- b: &'static [S],
- ary: &mut [MaybeUninit<S>],
-)
- -> &'static [S]
-{
-// unsafe {
-
-// }
- panic!()
-}
-
-struct Outer { o: usize, }
-impl Ish for Outer {
- const N: usize = Inner::N + 1;
- const F: &'static [S] = {
- static mut ARY: [MaybeUninit<S>; Inner::N + 1] = [MaybeUninit::uninit(); Inner::N + 1];
-
- plus::<{Inner::N + 1}>(
- Inner::F,
- &["o"],
- &mut ARY[..],
- )
- };
+impl<const N: usize, T> AutoStackVec<N,T> {
+ fn new() -> Self where T: Default {
+ AutoStackVec {
+ used: 0,
+ buf: std::array::from_fn(|_| default()),
+ }
+ }
}
-*/
fn main(){
- eprintln!("IF {:?}", Inner::F);
- eprintln!("OF {:?}", Outer::F);
+ let asv = AutoStackVec::<4, i32>::new();
+ eprintln!("N {:?}", asv);
}