Skip to main content

embedded_cal/util/
mod.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2// SPDX-FileCopyrightText: Inria-AIO, Cryspen, and Christian Amsüss
3//! Tools helpful in implementing `embedded-cal`
4
5pub mod aesccm;
6pub mod montgomery;
7pub mod p256;
8
9/// A 2-variant generic enum, useful for writing implementations that provide some own variants on
10/// those passed on directly to a base.
11///
12/// It implements various traits depending on the own and base trait; currently, just as `AsRef`.
13///
14/// # Caveats
15///
16/// **Do not use this to** extend own enums, as those will become types with their fixed layout that
17/// might easily use the very same discriminator field as the underlying type, and thus defeat
18/// possible optimizations.
19#[derive(Debug, Clone, PartialEq, Eq)]
20pub enum Either<Own, Base> {
21    Own(Own),
22    Direct(Base),
23}
24
25impl<T: ?Sized, Own: AsRef<T>, Base: AsRef<T>> AsRef<T> for Either<Own, Base> {
26    fn as_ref(&self) -> &T {
27        match self {
28            Either::Own(o) => o.as_ref(),
29            Either::Direct(d) => d.as_ref(),
30        }
31    }
32}