use core::fmt::Display;
use miden_crypto_derive::WordWrapper;
use crate::Word;
use crate::utils::serde::{
ByteReader,
ByteWriter,
Deserializable,
DeserializationError,
Serializable,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, WordWrapper)]
pub struct AssetValue(Word);
impl AssetValue {
pub const SERIALIZED_SIZE: usize = Word::SERIALIZED_SIZE;
}
impl From<AssetValue> for Word {
fn from(value: AssetValue) -> Self {
value.0
}
}
impl Display for AssetValue {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_word())
}
}
impl Serializable for AssetValue {
fn write_into<W: ByteWriter>(&self, target: &mut W) {
target.write_many(self.as_word());
}
fn get_size_hint(&self) -> usize {
Self::SERIALIZED_SIZE
}
}
impl Deserializable for AssetValue {
fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
Ok(AssetValue::from_raw(source.read()?))
}
}