arnaucube
arnaucube/plonky2-u32Public Self-hosted repository
plonky2-u32/src/serialization.rs
src/serialization.rsRaw
 1use alloc::vec::Vec;
 2use plonky2::util::serialization::{Buffer, IoResult, Read, Write};
 3
 4use crate::gadgets::arithmetic_u32::U32Target;
 5
 6pub trait WriteU32 {
 7    fn write_target_u32(&mut self, x: U32Target) -> IoResult<()>;
 8}
 9
10impl WriteU32 for Vec<u8> {
11    #[inline]
12    fn write_target_u32(&mut self, x: U32Target) -> IoResult<()> {
13        self.write_target(x.0)
14    }
15}
16
17pub trait ReadU32 {
18    fn read_target_u32(&mut self) -> IoResult<U32Target>;
19}
20
21impl ReadU32 for Buffer {
22    #[inline]
23    fn read_target_u32(&mut self) -> IoResult<U32Target> {
24        Ok(U32Target(self.read_target()?))
25    }
26}