@@ -38,6 +38,27 @@ pub trait ToBits {
3838 fn write_bits_be ( & self , vec : & mut Vec < Self :: Boolean > ) ;
3939}
4040
41+ /// Unary operator for converting to raw bits.
42+ pub trait ToBitsRaw : ToBits {
43+ /// Returns the little-endian bits without variant or identifier bits of the circuit.
44+ fn to_bits_raw_le ( & self ) -> Vec < Self :: Boolean > {
45+ let mut bits = vec ! [ ] ;
46+ self . write_bits_raw_le ( & mut bits) ;
47+ bits
48+ }
49+
50+ fn write_bits_raw_le ( & self , vec : & mut Vec < Self :: Boolean > ) ;
51+
52+ /// Returns the bits-endian bits without variant or identifier bits of the circuit.
53+ fn to_bits_raw_be ( & self ) -> Vec < Self :: Boolean > {
54+ let mut bits = vec ! [ ] ;
55+ self . write_bits_raw_be ( & mut bits) ;
56+ bits
57+ }
58+
59+ fn write_bits_raw_be ( & self , vec : & mut Vec < Self :: Boolean > ) ;
60+ }
61+
4162/********************/
4263/****** Arrays ******/
4364/********************/
@@ -100,6 +121,58 @@ impl<C: ToBits<Boolean = B>, B: BooleanTrait> ToBits for &[C] {
100121 }
101122}
102123
124+ impl < C : ToBitsRaw < Boolean = B > , B : BooleanTrait > ToBitsRaw for Vec < C > {
125+ /// A helper method to return a concatenated list of little-endian bits without variant or identifier bits from the circuits.
126+ #[ inline]
127+ fn write_bits_raw_le ( & self , vec : & mut Vec < Self :: Boolean > ) {
128+ // The vector is order-preserving, meaning the first circuit in is the first circuit bits out.
129+ self . as_slice ( ) . write_bits_raw_le ( vec) ;
130+ }
131+
132+ /// A helper method to return a concatenated list of bits-endian bits without variant or identifier bits from the circuits.
133+ #[ inline]
134+ fn write_bits_raw_be ( & self , vec : & mut Vec < Self :: Boolean > ) {
135+ // The vector is order-preserving, meaning the first circuit in is the first circuit bits out.
136+ self . as_slice ( ) . write_bits_raw_be ( vec) ;
137+ }
138+ }
139+
140+ impl < C : ToBitsRaw < Boolean = B > , B : BooleanTrait , const N : usize > ToBitsRaw for [ C ; N ] {
141+ /// A helper method to return a concatenated list of little-endian bits without variant or identifier bits from the circuits.
142+ #[ inline]
143+ fn write_bits_raw_le ( & self , vec : & mut Vec < Self :: Boolean > ) {
144+ // The slice is order-preserving, meaning the first circuit in is the first circuit bits out.
145+ self . as_slice ( ) . write_bits_raw_le ( vec) ;
146+ }
147+
148+ /// A helper method to return a concatenated list of bits-endian bits without variant or identifier bits from the circuits.
149+ #[ inline]
150+ fn write_bits_raw_be ( & self , vec : & mut Vec < Self :: Boolean > ) {
151+ // The slice is order-preserving, meaning the first circuit in is the first circuit bits out.
152+ self . as_slice ( ) . write_bits_raw_be ( vec) ;
153+ }
154+ }
155+
156+ impl < C : ToBitsRaw < Boolean = B > , B : BooleanTrait > ToBitsRaw for & [ C ] {
157+ /// A helper method to return a concatenated list of little-endian bits without variant or identifier bits from the circuits.
158+ #[ inline]
159+ fn write_bits_raw_le ( & self , vec : & mut Vec < Self :: Boolean > ) {
160+ // The slice is order-preserving, meaning the first circuit in is the first circuit bits out.
161+ for elem in self . iter ( ) {
162+ elem. write_bits_raw_le ( vec) ;
163+ }
164+ }
165+
166+ /// A helper method to return a concatenated list of bits-endian bits without variant or identifier bits from the circuits.
167+ #[ inline]
168+ fn write_bits_raw_be ( & self , vec : & mut Vec < Self :: Boolean > ) {
169+ // The slice is order-preserving, meaning the first circuit in is the first circuit bits out.
170+ for elem in self . iter ( ) {
171+ elem. write_bits_raw_be ( vec) ;
172+ }
173+ }
174+ }
175+
103176/********************/
104177/****** Tuples ******/
105178/********************/
@@ -144,6 +217,40 @@ macro_rules! to_bits_tuple {
144217 $( self . $idx. write_bits_be( vec) ; ) +
145218 }
146219 }
220+
221+ impl <B : BooleanTrait , $t0: ToBitsRaw <Boolean = B >, $( $ty: ToBitsRaw <Boolean = B >) ,+> ToBitsRaw for ( $t0, $( $ty) ,+) {
222+ /// A helper method to return a concatenated list of little-endian bits without variant or identifier bits from the circuits.
223+ #[ inline]
224+ fn write_bits_raw_le( & self , vec: & mut Vec <Self :: Boolean >) {
225+ // The tuple is order-preserving, meaning the first circuit in is the first circuit bits out.
226+ ( & self ) . write_bits_raw_le( vec) ;
227+ }
228+
229+ /// A helper method to return a concatenated list of bits-endian bits without variant or identifier bits from the circuits.
230+ #[ inline]
231+ fn write_bits_raw_be( & self , vec: & mut Vec <Self :: Boolean >) {
232+ // The tuple is order-preserving, meaning the first circuit in is the first circuit bits out.
233+ ( & self ) . write_bits_raw_be( vec) ;
234+ }
235+ }
236+
237+ impl <' a, B : BooleanTrait , $t0: ToBitsRaw <Boolean = B >, $( $ty: ToBitsRaw <Boolean = B >) ,+> ToBitsRaw for & ' a ( $t0, $( $ty) ,+) {
238+ /// A helper method to return a concatenated list of little-endian bits without variant or identifier bits from the circuits.
239+ #[ inline]
240+ fn write_bits_raw_le( & self , vec: & mut Vec <Self :: Boolean >) {
241+ // The tuple is order-preserving, meaning the first circuit in is the first circuit bits out.
242+ self . $i0. write_bits_raw_le( vec) ;
243+ $( self . $idx. write_bits_raw_le( vec) ; ) +
244+ }
245+
246+ /// A helper method to return a concatenated list of bits-endian bits without variant or identifier bits from the circuits.
247+ #[ inline]
248+ fn write_bits_raw_be( & self , vec: & mut Vec <Self :: Boolean >) {
249+ // The tuple is order-preserving, meaning the first circuit in is the first circuit bits out.
250+ self . $i0. write_bits_raw_be( vec) ;
251+ $( self . $idx. write_bits_raw_be( vec) ; ) +
252+ }
253+ }
147254 }
148255}
149256
0 commit comments