1use alloc::vec::Vec;
2use core::{
3 fmt::Debug,
4 ops::{Bound, Range},
5};
6
7pub use miden_crypto::utils::{
10 ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable, SliceReader,
11 collections, uninit_vector,
12};
13#[cfg(feature = "std")]
14pub use winter_utils::ReadAdapter;
15pub use winter_utils::group_slice_elements;
16
17use crate::Felt;
18
19pub mod math {
20 pub use winter_math::batch_inversion;
21}
22
23pub trait ToElements {
27 fn to_elements(&self) -> Vec<Felt>;
28}
29
30impl<const N: usize> ToElements for [u64; N] {
31 fn to_elements(&self) -> Vec<Felt> {
32 self.iter().map(|&v| Felt::new(v)).collect()
33 }
34}
35
36impl ToElements for Vec<u64> {
37 fn to_elements(&self) -> Vec<Felt> {
38 self.iter().map(|&v| Felt::new(v)).collect()
39 }
40}
41
42pub trait IntoBytes<const N: usize> {
46 fn into_bytes(self) -> [u8; N];
47}
48
49impl IntoBytes<32> for [Felt; 4] {
50 fn into_bytes(self) -> [u8; 32] {
51 let mut result = [0; 32];
52
53 result[..8].copy_from_slice(&self[0].as_int().to_le_bytes());
54 result[8..16].copy_from_slice(&self[1].as_int().to_le_bytes());
55 result[16..24].copy_from_slice(&self[2].as_int().to_le_bytes());
56 result[24..].copy_from_slice(&self[3].as_int().to_le_bytes());
57
58 result
59 }
60}
61
62pub trait PushMany<T> {
66 fn push_many(&mut self, value: T, n: usize);
67}
68
69impl<T: Copy> PushMany<T> for Vec<T> {
70 fn push_many(&mut self, value: T, n: usize) {
71 let new_len = self.len() + n;
72 self.resize(new_len, value);
73 }
74}
75
76pub const fn range(start: usize, len: usize) -> Range<usize> {
81 Range { start, end: start + len }
82}
83
84pub fn bound_into_included_u64<I>(bound: Bound<&I>, is_start: bool) -> u64
86where
87 I: Clone + Into<u64>,
88{
89 match bound {
90 Bound::Excluded(i) => i.clone().into().saturating_sub(1),
91 Bound::Included(i) => i.clone().into(),
92 Bound::Unbounded => {
93 if is_start {
94 0
95 } else {
96 u64::MAX
97 }
98 },
99 }
100}
101
102pub fn new_array_vec<T: Debug, const N: usize>(capacity: usize) -> [Vec<T>; N] {
107 (0..N)
108 .map(|_| Vec::with_capacity(capacity))
109 .collect::<Vec<_>>()
110 .try_into()
111 .expect("failed to convert vector to array")
112}
113
114#[test]
115#[should_panic]
116fn debug_assert_is_checked() {
117 debug_assert!(false);
125}
126
127pub use miden_formatting::hex::{DisplayHex, ToHex, to_hex};