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