subxt_core/custom_values/
address.rs1use crate::dynamic::DecodedValueThunk;
8use crate::metadata::DecodeWithMetadata;
9use derive_where::derive_where;
10
11pub use crate::utils::Yes;
13
14pub trait Address {
18 type Target: DecodeWithMetadata;
20 type IsDecodable;
23
24 fn name(&self) -> &str;
26
27 fn validation_hash(&self) -> Option<[u8; 32]> {
29 None
30 }
31}
32
33impl Address for str {
34 type Target = DecodedValueThunk;
35 type IsDecodable = Yes;
36
37 fn name(&self) -> &str {
38 self
39 }
40}
41
42#[derive_where(Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
44pub struct StaticAddress<ReturnTy, IsDecodable> {
45 name: &'static str,
46 hash: Option<[u8; 32]>,
47 phantom: core::marker::PhantomData<(ReturnTy, IsDecodable)>,
48}
49
50impl<ReturnTy, IsDecodable> StaticAddress<ReturnTy, IsDecodable> {
51 #[doc(hidden)]
52 pub fn new_static(name: &'static str, hash: [u8; 32]) -> StaticAddress<ReturnTy, IsDecodable> {
54 StaticAddress::<ReturnTy, IsDecodable> {
55 name,
56 hash: Some(hash),
57 phantom: core::marker::PhantomData,
58 }
59 }
60
61 pub fn unvalidated(self) -> Self {
63 Self {
64 name: self.name,
65 hash: None,
66 phantom: self.phantom,
67 }
68 }
69}
70
71impl<R: DecodeWithMetadata, Y> Address for StaticAddress<R, Y> {
72 type Target = R;
73 type IsDecodable = Y;
74
75 fn name(&self) -> &str {
76 self.name
77 }
78
79 fn validation_hash(&self) -> Option<[u8; 32]> {
80 self.hash
81 }
82}