alloy_sol_types/
lib.rs

1#![doc = include_str!("../README.md")]
2#![doc(
3    html_logo_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/alloy.jpg",
4    html_favicon_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/favicon.ico"
5)]
6#![cfg_attr(not(test), warn(unused_crate_dependencies))]
7#![cfg_attr(not(feature = "std"), no_std)]
8#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
9
10#[allow(unused_extern_crates)]
11extern crate self as alloy_sol_types;
12
13#[macro_use]
14extern crate alloc;
15
16#[macro_use]
17mod macros;
18
19pub mod abi;
20
21mod errors;
22pub use errors::{Error, Result};
23
24#[cfg(feature = "json")]
25mod ext;
26#[cfg(feature = "json")]
27pub use ext::JsonAbiExt;
28
29mod impl_core;
30
31mod types;
32pub use types::{
33    data_type as sol_data, decode_revert_reason, ContractError, EventTopic, GenericContractError,
34    GenericRevertReason, Panic, PanicKind, Revert, RevertReason, Selectors, SolCall,
35    SolConstructor, SolEnum, SolError, SolEvent, SolEventInterface, SolInterface, SolStruct,
36    SolType, SolValue, TopicList,
37};
38
39pub mod utils;
40
41mod eip712;
42pub use eip712::Eip712Domain;
43
44/// The ABI word type.
45pub type Word = alloy_primitives::B256;
46
47#[doc(no_inline)]
48pub use alloy_sol_macro::sol;
49
50// Not public API.
51#[doc(hidden)]
52#[allow(missing_debug_implementations)]
53pub mod private {
54    pub use super::{
55        abi::RECURSION_LIMIT,
56        utils::{just_ok, next_multiple_of_32, words_for, words_for_len},
57    };
58    pub use alloc::{
59        borrow::{Cow, ToOwned},
60        boxed::Box,
61        collections::BTreeMap,
62        string::{String, ToString},
63        vec,
64        vec::Vec,
65    };
66    pub use alloy_primitives::{
67        self as primitives, bytes, keccak256, Address, Bytes, FixedBytes, Function, IntoLogData,
68        LogData, Signed, Uint, B256, I256, U256,
69    };
70    pub use core::{
71        borrow::{Borrow, BorrowMut},
72        convert::From,
73        default::Default,
74        option::Option,
75        result::Result,
76    };
77
78    pub use Option::{None, Some};
79    pub use Result::{Err, Ok};
80
81    #[cfg(feature = "json")]
82    pub use alloy_json_abi;
83
84    /// An ABI-encodable is any type that may be encoded via a given `SolType`.
85    ///
86    /// The `SolType` trait contains encoding logic for a single associated
87    /// `RustType`. This trait allows us to plug in encoding logic for other
88    /// `RustTypes`.
89    ///
90    /// **Note:** this trait is an implementation detail. As such, it should not
91    /// be implemented directly unless implementing a custom
92    /// [`SolType`](crate::SolType), which is also discouraged. Consider
93    /// using [`SolValue`](crate::SolValue) instead.
94    pub trait SolTypeValue<T: super::SolType> {
95        // Note: methods are prefixed with `stv_` to avoid name collisions with
96        // the `SolValue` trait.
97
98        #[inline(always)]
99        fn stv_abi_encoded_size(&self) -> usize {
100            T::ENCODED_SIZE.unwrap()
101        }
102        fn stv_to_tokens(&self) -> T::Token<'_>;
103
104        #[inline(always)]
105        fn stv_abi_packed_encoded_size(&self) -> usize {
106            T::PACKED_ENCODED_SIZE.unwrap()
107        }
108        fn stv_abi_encode_packed_to(&self, out: &mut Vec<u8>);
109
110        fn stv_eip712_data_word(&self) -> super::Word;
111    }
112
113    #[inline(always)]
114    pub const fn u256(n: u64) -> U256 {
115        U256::from_limbs([n, 0, 0, 0])
116    }
117
118    pub struct AssertTypeEq<T>(pub T);
119}