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