hyperplonk/subroutines/src/poly_iop/utils.rs
subroutines/src/poly_iop/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#[cfg(test)]
15mod test {
16 use ark_bls12_381::Fr;
17 use ark_serialize::CanonicalSerialize;
18 use ark_std::One;
19
20 #[test]
21 fn test_to_bytes() {
22 let f1 = Fr::one();
23
24 let mut bytes = ark_std::vec![];
25 f1.serialize(&mut bytes).unwrap();
26 assert_eq!(bytes, to_bytes!(&f1).unwrap());
27 }
28}