pub trait Token<'de>: Sealed + Sized {
const DYNAMIC: bool;
// Required methods
fn decode_from(dec: &mut Decoder<'de>) -> Result<Self>;
fn head_words(&self) -> usize;
fn tail_words(&self) -> usize;
fn head_append(&self, enc: &mut Encoder);
fn tail_append(&self, enc: &mut Encoder);
// Provided method
fn total_words(&self) -> usize { ... }
}
Expand description
Ethereum ABI tokens.
Tokens are an intermediate state between ABI-encoded blobs, and Rust types.
ABI encoding uses 5 types:
WordToken
: Single EVM words (a 32-byte string)FixedSeqToken
: Sequences with a fixed lengthT[M]
DynSeqToken
: Sequences with a dynamic lengthT[]
PackedSeqToken
: Dynamic-length byte arraysbytes
orstring
- Tuples
(T, U, V, ...)
(implemented for arity0..=24
)
A token with a lifetime borrows its data from elsewhere. During decoding, it borrows its data from the decoder. During encoding, it borrows its data from the Rust value being encoded.
This trait allows us to encode and decode data with minimal copying. It may also be used to enable zero-copy decoding of data, or fast transformation of encoded blobs without full decoding.
This trait is sealed and cannot be implemented for types outside of this crate. It is implemented only for the types listed above.
Required Associated Constants§
Required Methods§
Sourcefn decode_from(dec: &mut Decoder<'de>) -> Result<Self>
fn decode_from(dec: &mut Decoder<'de>) -> Result<Self>
Decode a token from a decoder.
Sourcefn head_words(&self) -> usize
fn head_words(&self) -> usize
Calculate the number of head words.
Sourcefn tail_words(&self) -> usize
fn tail_words(&self) -> usize
Calculate the number of tail words.
Sourcefn head_append(&self, enc: &mut Encoder)
fn head_append(&self, enc: &mut Encoder)
Append head words to the encoder.
Sourcefn tail_append(&self, enc: &mut Encoder)
fn tail_append(&self, enc: &mut Encoder)
Append tail words to the encoder.
Provided Methods§
Sourcefn total_words(&self) -> usize
fn total_words(&self) -> usize
Calculate the total number of head and tail words.
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.