mdnt_groups_support/
lib.rs

1#![doc = include_str!("../README.md")]
2//!
3//! Includes some implementations of the [`DecomposeIn<Cell>`] trait for standard
4//! types but is not exhaustive. The implemented types cover the needs of the
5//! circuits crate.
6//!
7//! If other external types are required their implementation should be added to
8//! this crate.
9
10#![deny(rustdoc::broken_intra_doc_links)]
11#![deny(missing_debug_implementations)]
12#![deny(missing_docs)]
13
14/// Implementations of this trait represent complex types that aggregate a
15/// collection of `AssignedCell` values.
16pub trait DecomposeIn<Cell> {
17    /// Returns an iterator of `Cell` instances.
18    fn cells(&self) -> impl IntoIterator<Item = Cell>;
19}
20
21impl<Cell> DecomposeIn<Cell> for u32 {
22    fn cells(&self) -> impl IntoIterator<Item = Cell> {
23        std::iter::empty()
24    }
25}
26
27impl<Cell, T: DecomposeIn<Cell>, E> DecomposeIn<Cell> for Result<T, E> {
28    fn cells(&self) -> impl IntoIterator<Item = Cell> {
29        self.iter().flat_map(|t| t.cells())
30    }
31}
32
33impl<Cell, T: DecomposeIn<Cell>> DecomposeIn<Cell> for Option<T> {
34    fn cells(&self) -> impl IntoIterator<Item = Cell> {
35        self.iter().flat_map(|t| t.cells())
36    }
37}
38
39impl<Cell, T: DecomposeIn<Cell>> DecomposeIn<Cell> for &[T] {
40    fn cells(&self) -> impl IntoIterator<Item = Cell> {
41        self.iter().flat_map(|t| t.cells())
42    }
43}
44
45impl<Cell, T: DecomposeIn<Cell>, const N: usize> DecomposeIn<Cell> for [T; N] {
46    fn cells(&self) -> impl IntoIterator<Item = Cell> {
47        self.iter().flat_map(|t| t.cells())
48    }
49}
50
51impl<Cell, T: DecomposeIn<Cell>> DecomposeIn<Cell> for Vec<T> {
52    fn cells(&self) -> impl IntoIterator<Item = Cell> {
53        self.iter().flat_map(|t| t.cells())
54    }
55}