twenty_first/
lib.rs

1#![deny(clippy::shadow_unrelated)]
2pub mod config;
3pub mod error;
4pub mod math;
5pub mod prelude;
6pub mod util_types;
7
8// This is needed for `#[derive(BFieldCodec)]` macro to work consistently across crates.
9// Specifically:
10// From inside the `twenty-first` crate, we need to refer to `twenty-first` by `crate`.
11// However, from outside the `twenty-first` crate, we need to refer to it by `twenty_first`.
12// The re-export below allows using identifier `twenty_first` even from inside `twenty-first`.
13//
14// See also:
15// https://github.com/bkchr/proc-macro-crate/issues/2#issuecomment-572914520
16extern crate self as twenty_first;
17
18// re-export crates used in our public API
19pub use bfieldcodec_derive;
20
21#[cfg(test)]
22pub(crate) mod tests {
23    use prelude::*;
24
25    use super::*;
26
27    /// The compiler automatically adds any applicable auto trait (all of which are
28    /// marker traits) to self-defined types. This implies that these trait bounds
29    /// might vanish if the necessary pre-conditions are no longer met. That'd be a
30    /// breaking API change!
31    ///
32    /// To prevent _accidental_ removal of auto trait implementations, this method
33    /// tests for their presence. If you are re-designing any of the types below
34    /// and a test fails as a result, that might be fine. You are now definitely
35    /// aware of a consequence you might not have known about otherwise. (If you
36    /// were already aware you know how subtle this stuff can be and are hopefully
37    /// fine with reading this comment.)
38    ///
39    /// Inspired by “Rust for Rustaceans” by Jon Gjengset.
40    pub fn implements_usual_auto_traits<T: Sized + Send + Sync + Unpin>() {}
41
42    #[test]
43    fn types_in_prelude_implement_the_usual_auto_traits() {
44        implements_usual_auto_traits::<BFieldElement>();
45        implements_usual_auto_traits::<Polynomial<BFieldElement>>();
46        implements_usual_auto_traits::<Polynomial<XFieldElement>>();
47        implements_usual_auto_traits::<Digest>();
48        implements_usual_auto_traits::<Tip5>();
49        implements_usual_auto_traits::<XFieldElement>();
50        implements_usual_auto_traits::<MerkleTree>();
51        implements_usual_auto_traits::<MerkleTreeInclusionProof>();
52        implements_usual_auto_traits::<MmrMembershipProof>();
53    }
54
55    #[test]
56    fn public_types_implement_the_usual_auto_traits() {
57        implements_usual_auto_traits::<math::lattice::CyclotomicRingElement>();
58        implements_usual_auto_traits::<math::lattice::ModuleElement<42>>();
59        implements_usual_auto_traits::<math::lattice::kem::SecretKey>();
60        implements_usual_auto_traits::<math::lattice::kem::PublicKey>();
61        implements_usual_auto_traits::<math::lattice::kem::Ciphertext>();
62        implements_usual_auto_traits::<util_types::sponge::Domain>();
63        implements_usual_auto_traits::<util_types::mmr::mmr_accumulator::MmrAccumulator>();
64        implements_usual_auto_traits::<math::zerofier_tree::Branch<BFieldElement>>();
65        implements_usual_auto_traits::<math::zerofier_tree::Leaf<BFieldElement>>();
66        implements_usual_auto_traits::<math::zerofier_tree::ZerofierTree<BFieldElement>>();
67        implements_usual_auto_traits::<
68            math::polynomial::ModularInterpolationPreprocessingData<BFieldElement>,
69        >();
70    }
71
72    #[test]
73    fn errors_implement_the_usual_auto_traits() {
74        implements_usual_auto_traits::<error::BFieldCodecError>();
75        implements_usual_auto_traits::<error::PolynomialBFieldCodecError>();
76        implements_usual_auto_traits::<error::MerkleTreeError>();
77        implements_usual_auto_traits::<error::ParseBFieldElementError>();
78        implements_usual_auto_traits::<error::TryFromDigestError>();
79        implements_usual_auto_traits::<error::TryFromHexDigestError>();
80        implements_usual_auto_traits::<error::TryFromU32sError>();
81        implements_usual_auto_traits::<error::TryFromXFieldElementError>();
82    }
83}