|
| 1 | +use openvm_circuit_primitives_derive::AlignedBorrow; |
| 2 | +use openvm_sha_macros::ColsRef; |
| 3 | + |
| 4 | +mod test_config; |
| 5 | +use test_config::{TestConfig, TestConfigImpl}; |
| 6 | + |
| 7 | +#[derive(ColsRef)] |
| 8 | +#[config(TestConfig)] |
| 9 | +struct TestCols<T, const N: usize> { |
| 10 | + a: [T; N], |
| 11 | + // Forces the field to be treated as a struct that derives AlignedBorrow. |
| 12 | + // In particular, ignores the fact that it ends with `Cols` and doesn't |
| 13 | + // expect a `PlainTestColsRef` type. |
| 14 | + #[plain] |
| 15 | + b: PlainCols<T>, |
| 16 | +} |
| 17 | + |
| 18 | +#[derive(Clone, Copy, Debug, AlignedBorrow)] |
| 19 | +struct PlainCols<T> { |
| 20 | + a: T, |
| 21 | + b: [T; 4], |
| 22 | +} |
| 23 | + |
| 24 | +#[test] |
| 25 | +fn plain() { |
| 26 | + let input = [1; TestConfigImpl::N + 1 + 4]; |
| 27 | + let test: TestColsRef<u32> = TestColsRef::from::<TestConfigImpl>(&input); |
| 28 | + println!("{}", test.a); |
| 29 | + println!("{:?}", test.b); |
| 30 | +} |
| 31 | + |
| 32 | +#[test] |
| 33 | +fn plain_mut() { |
| 34 | + let mut input = [1; TestConfigImpl::N + 1 + 4]; |
| 35 | + let mut test: TestColsRefMut<u32> = TestColsRefMut::from::<TestConfigImpl>(&mut input); |
| 36 | + test.a[0] = 1; |
| 37 | + test.b.a = 1; |
| 38 | + test.b.b[0] = 1; |
| 39 | + println!("{}", test.a); |
| 40 | + println!("{:?}", test.b); |
| 41 | +} |
| 42 | + |
| 43 | +#[test] |
| 44 | +fn plain_from_mut() { |
| 45 | + let mut input = [1; TestConfigImpl::N + 1 + 4]; |
| 46 | + let mut test: TestColsRefMut<u32> = TestColsRefMut::from::<TestConfigImpl>(&mut input); |
| 47 | + test.a[0] = 1; |
| 48 | + test.b.a = 1; |
| 49 | + test.b.b[0] = 1; |
| 50 | + let test2: TestColsRef<u32> = TestColsRef::from_mut::<TestConfigImpl>(&mut test); |
| 51 | + println!("{}", test2.a); |
| 52 | + println!("{:?}", test2.b); |
| 53 | +} |
0 commit comments