From: Ian Jackson Date: Wed, 17 Aug 2022 13:28:01 +0000 (+0100) Subject: asv X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=2c3449c702268463836de05986061c2e6a2d7721;p=rust-experiments.git asv --- diff --git a/src/main.rs b/src/main.rs index d5e0cbd..476e59c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,80 +5,24 @@ use std::mem; use std::mem::MaybeUninit; -type S = &'static str; +pub fn default() -> T { Default::default() } - -#[repr(C)] -struct Concat( - [S; A], - [S; B], -); - -trait Ish { - const N: usize; -} - -trait Has { - 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 { + 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 -(x: &'static [S], - b: &'static [S], - ary: &mut [MaybeUninit], -) - -> &'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; Inner::N + 1] = [MaybeUninit::uninit(); Inner::N + 1]; - - plus::<{Inner::N + 1}>( - Inner::F, - &["o"], - &mut ARY[..], - ) - }; +impl AutoStackVec { + 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); }