honeycomb_core/cmap/components/
orbits.rs

1/// # Orbit search policy enum
2///
3/// This is used to define special cases of orbits that are often used in
4/// algorithms. These special cases correspond to `i`-cells.
5#[derive(Debug, PartialEq, Clone)]
6pub enum OrbitPolicy {
7    /// 0-cell orbit.
8    Vertex,
9    /// 0-cell orbit, without using beta 0. Incorrect if the cell isn't complete / closed.
10    VertexLinear,
11    /// 1-cell orbit.
12    Edge,
13    /// 2-cell orbit.
14    Face,
15    /// 2-cell orbit, without using beta 0. Incorrect if the cell isn't complete / closed.
16    FaceLinear,
17    /// 3-cell orbit.
18    Volume,
19    /// 3-cell orbit, without using beta 0. Incorrect if the cell isn't complete / closed.
20    VolumeLinear,
21    /// Ordered array of beta functions defining the orbit.
22    Custom(&'static [u8]),
23}
24
25/// Custom fallible `unfold` iterator.
26///
27/// This doesn't solve usability issues, but it reduces internal boilerplate by
28/// allowing the usage of `?` inside the closure.
29///
30/// Modelled after [`std::iter::FromFn`].
31#[derive(Clone)]
32pub(crate) struct TryFromFn<F>(F);
33
34impl<T, E, F> Iterator for TryFromFn<F>
35where
36    F: FnMut() -> Result<Option<T>, E>,
37{
38    type Item = Result<T, E>;
39
40    fn next(&mut self) -> Option<Self::Item> {
41        match (self.0)() {
42            Ok(Some(value)) => Some(Ok(value)), // Yield a successful item
43            Ok(None) => None,                   // End iteration
44            Err(e) => Some(Err(e)),             // Yield an error
45        }
46    }
47}
48
49pub(crate) fn try_from_fn<T, E, F>(f: F) -> TryFromFn<F>
50where
51    F: FnMut() -> Result<Option<T>, E>,
52{
53    TryFromFn(f)
54}