hyperplonk/poly-iop/src/utils.rs
poly-iop/src/utils.rsRaw
1//! useful macros.
2
3/// Takes as input a struct, and converts them to a series of bytes. All traits
4/// that implement `CanonicalSerialize` can be automatically converted to bytes
5/// in this manner.
6#[macro_export]
7macro_rules! to_bytes {
8 ($x:expr) => {{
9 let mut buf = ark_std::vec![];
10 ark_serialize::CanonicalSerialize::serialize($x, &mut buf).map(|_| buf)
11 }};
12}
13
14#[test]
15fn test_to_bytes() {
16 use ark_bls12_381::Fr;
17 use ark_serialize::CanonicalSerialize;
18 use ark_std::One;
19 let f1 = Fr::one();
20
21 let mut bytes = ark_std::vec![];
22 f1.serialize(&mut bytes).unwrap();
23 assert_eq!(bytes, to_bytes!(&f1).unwrap());
24}