sized_chunks/
types.rs

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/.
4
5//! Helper types for chunks.
6
7use core::marker::PhantomData;
8
9use typenum::*;
10
11// Chunk sizes
12
13/// 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`.
19    type SizedType;
20}
21
22impl<A> ChunkLength<A> for UTerm {
23    type SizedType = ();
24}
25
26#[doc(hidden)]
27#[allow(dead_code)]
28pub struct SizeEven<A, B> {
29    parent1: B,
30    parent2: B,
31    _marker: PhantomData<A>,
32}
33
34#[doc(hidden)]
35#[allow(dead_code)]
36pub struct SizeOdd<A, B> {
37    parent1: B,
38    parent2: B,
39    data: A,
40}
41
42impl<A, N> ChunkLength<A> for UInt<N, B0>
43where
44    N: ChunkLength<A>,
45{
46    type SizedType = SizeEven<A, N::SizedType>;
47}
48
49impl<A, N> ChunkLength<A> for UInt<N, B1>
50where
51    N: ChunkLength<A>,
52{
53    type SizedType = SizeOdd<A, N::SizedType>;
54}