miden-crypto/src/utils/mod.rs
src/utils/mod.rsRaw
1use super::{utils::string::String, Word};
2use core::fmt::{self, Write};
3
4#[cfg(not(feature = "std"))]
5pub use alloc::format;
6
7#[cfg(feature = "std")]
8pub use std::format;
9
10mod diff;
11mod kv_map;
12
13// RE-EXPORTS
14// ================================================================================================
15pub use winter_utils::{
16 string, uninit_vector, Box, ByteReader, ByteWriter, Deserializable, DeserializationError,
17 Serializable, SliceReader,
18};
19
20pub mod collections {
21 pub use super::diff::*;
22 pub use super::kv_map::*;
23 pub use winter_utils::collections::*;
24}
25
26// UTILITY FUNCTIONS
27// ================================================================================================
28
29/// Converts a [Word] into hex.
30pub fn word_to_hex(w: &Word) -> Result<String, fmt::Error> {
31 let mut s = String::new();
32
33 for byte in w.iter().flat_map(|e| e.to_bytes()) {
34 write!(s, "{byte:02x}")?;
35 }
36
37 Ok(s)
38}