pub trait SolInterface: Sized {
const NAME: &'static str;
const MIN_DATA_LENGTH: usize;
const COUNT: usize;
// Required methods
fn selector(&self) -> [u8; 4];
fn selector_at(i: usize) -> Option<[u8; 4]>;
fn valid_selector(selector: [u8; 4]) -> bool;
fn abi_decode_raw(
selector: [u8; 4],
data: &[u8],
validate: bool,
) -> Result<Self>;
fn abi_encoded_size(&self) -> usize;
fn abi_encode_raw(&self, out: &mut Vec<u8>);
// Provided methods
fn type_check(selector: [u8; 4]) -> Result<()> { ... }
fn selectors() -> Selectors<Self> ⓘ { ... }
fn abi_encode(&self) -> Vec<u8> ⓘ { ... }
fn abi_decode(data: &[u8], validate: bool) -> Result<Self> { ... }
}
Expand description
A collection of ABI-encodable call-like types. This currently includes
SolCall
and SolError
.
This trait assumes that the implementing type always has a selector, and thus encoded/decoded data is always at least 4 bytes long.
This trait is implemented for Infallible
to represent an empty
interface. This is used by GenericContractError
.
§Implementer’s Guide
It should not be necessary to implement this trait manually. Instead, use
the sol!
procedural macro to parse Solidity syntax into
types that implement this trait.
Required Associated Constants§
Sourceconst MIN_DATA_LENGTH: usize
const MIN_DATA_LENGTH: usize
The minimum length of the data for this type.
This does not include the selector’s length (4).
Required Methods§
Sourcefn selector_at(i: usize) -> Option<[u8; 4]>
fn selector_at(i: usize) -> Option<[u8; 4]>
The selector of this type at the given index, used in
selectors
.
This must return None
if i >= Self::COUNT
, and Some
with a
different selector otherwise.
Sourcefn valid_selector(selector: [u8; 4]) -> bool
fn valid_selector(selector: [u8; 4]) -> bool
Returns true
if the given selector is known to this type.
Sourcefn abi_decode_raw(
selector: [u8; 4],
data: &[u8],
validate: bool,
) -> Result<Self>
fn abi_decode_raw( selector: [u8; 4], data: &[u8], validate: bool, ) -> Result<Self>
ABI-decodes the given data into one of the variants of self
.
Sourcefn abi_encoded_size(&self) -> usize
fn abi_encoded_size(&self) -> usize
The size of the encoded data, without any selectors.
Sourcefn abi_encode_raw(&self, out: &mut Vec<u8>)
fn abi_encode_raw(&self, out: &mut Vec<u8>)
ABI-encodes self
into the given buffer, without any selectors.
Provided Methods§
Sourcefn type_check(selector: [u8; 4]) -> Result<()>
fn type_check(selector: [u8; 4]) -> Result<()>
Returns an error if the given selector is not known to this type.
Sourcefn abi_encode(&self) -> Vec<u8> ⓘ
fn abi_encode(&self) -> Vec<u8> ⓘ
ABI-encodes self
into the given buffer.
Sourcefn abi_decode(data: &[u8], validate: bool) -> Result<Self>
fn abi_decode(data: &[u8], validate: bool) -> Result<Self>
ABI-decodes the given data into one of the variants of self
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl SolInterface for Infallible
impl SolInterface for Infallible
An empty SolInterface
implementation. Used by GenericContractError
.