stratus/eth/primitives/
slot_value.rs1use std::fmt::Display;
2
3use alloy_primitives::U256;
4use display_json::DebugAsJson;
5#[cfg(test)]
6use fake::Dummy;
7#[cfg(test)]
8use fake::Faker;
9
10#[derive(DebugAsJson, Clone, Copy, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
11pub struct SlotValue(pub U256);
12
13impl SlotValue {
14 pub fn as_u256(&self) -> U256 {
16 self.0
17 }
18}
19
20impl Display for SlotValue {
21 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22 write!(f, "{:#x}", self.0)
23 }
24}
25
26#[cfg(test)]
27impl Dummy<Faker> for SlotValue {
28 fn dummy_with_rng<R: rand::Rng + ?Sized>(_: &Faker, rng: &mut R) -> Self {
29 Self(U256::random_with(rng))
30 }
31}
32
33impl From<SlotValue> for U256 {
38 fn from(value: SlotValue) -> Self {
39 value.0
40 }
41}
42
43impl From<U256> for SlotValue {
48 fn from(value: U256) -> Self {
49 Self(value)
50 }
51}
52
53impl From<[u64; 4]> for SlotValue {
54 fn from(value: [u64; 4]) -> Self {
55 Self(U256::from_limbs(value))
56 }
57}
58
59impl From<alloy_primitives::FixedBytes<32>> for SlotValue {
60 fn from(value: alloy_primitives::FixedBytes<32>) -> Self {
61 Self::from(U256::from_be_bytes(value.0))
62 }
63}