1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at http://mozilla.org/MPL/2.0/.
45//! Helper types for chunks.
67use core::marker::PhantomData;
89use typenum::*;
1011// Chunk sizes
1213/// A trait used to decide the size of an array.
14///
15/// `<N as ChunkLength<A>>::SizedType` for a type level integer N will have the
16/// same size as `[A; N]`.
17pub trait ChunkLength<A>: Unsigned {
18/// A `Sized` type matching the size of an array of `Self` elements of `A`.
19type SizedType;
20}
2122impl<A> ChunkLength<A> for UTerm {
23type SizedType = ();
24}
2526#[doc(hidden)]
27#[allow(dead_code)]
28pub struct SizeEven<A, B> {
29 parent1: B,
30 parent2: B,
31 _marker: PhantomData<A>,
32}
3334#[doc(hidden)]
35#[allow(dead_code)]
36pub struct SizeOdd<A, B> {
37 parent1: B,
38 parent2: B,
39 data: A,
40}
4142impl<A, N> ChunkLength<A> for UInt<N, B0>
43where
44N: ChunkLength<A>,
45{
46type SizedType = SizeEven<A, N::SizedType>;
47}
4849impl<A, N> ChunkLength<A> for UInt<N, B1>
50where
51N: ChunkLength<A>,
52{
53type SizedType = SizeOdd<A, N::SizedType>;
54}