stratus/eth/primitives/
difficulty.rs1use alloy_primitives::U256;
2use display_json::DebugAsJson;
3use fake::Dummy;
4use fake::Faker;
5
6#[derive(DebugAsJson, derive_more::Display, Clone, Copy, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
7#[serde(transparent)]
8pub struct Difficulty(pub U256);
9
10impl Dummy<Faker> for Difficulty {
11 fn dummy_with_rng<R: rand::Rng + ?Sized>(_: &Faker, rng: &mut R) -> Self {
12 rng.next_u64().into()
13 }
14}
15
16impl From<u8> for Difficulty {
21 fn from(value: u8) -> Self {
22 Self(U256::from(value))
23 }
24}
25
26impl From<u16> for Difficulty {
27 fn from(value: u16) -> Self {
28 Self(U256::from(value))
29 }
30}
31
32impl From<u32> for Difficulty {
33 fn from(value: u32) -> Self {
34 Self(U256::from(value))
35 }
36}
37
38impl From<u64> for Difficulty {
39 fn from(value: u64) -> Self {
40 Self(U256::from(value))
41 }
42}
43
44impl From<u128> for Difficulty {
45 fn from(value: u128) -> Self {
46 Self(U256::from(value))
47 }
48}
49
50impl From<U256> for Difficulty {
51 fn from(value: U256) -> Self {
52 Self(value)
53 }
54}
55
56impl From<usize> for Difficulty {
57 fn from(value: usize) -> Self {
58 Self(U256::from(value))
59 }
60}
61
62impl From<i32> for Difficulty {
63 fn from(value: i32) -> Self {
64 Self(U256::from(value as u32))
65 }
66}
67
68impl From<[u64; 4]> for Difficulty {
69 fn from(value: [u64; 4]) -> Self {
70 Self(U256::from_limbs(value))
71 }
72}