pub trait SolEncode<'a> {
type SolType: SolTypeEncode + SolTopicEncode;
const SOL_NAME: &'static str = <<Self::SolType as SolTypeEncode>::AlloyType as AlloySolType>::SOL_NAME;
// Required method
fn to_sol_type(&'a self) -> Self::SolType;
// Provided methods
fn encode(&'a self) -> Vec<u8> ⓘ { ... }
fn encode_to(&'a self, buffer: &mut [u8]) -> usize { ... }
fn encode_topic<H>(&'a self, hasher: H) -> [u8; 32]
where H: Fn(&[u8], &mut [u8; 32]) { ... }
}Expand description
Maps an arbitrary Rust/ink! type to a Solidity ABI type equivalent for Solidity ABI encoding.
§Note
Implementing this trait entails:
- Declaring the equivalent Solidity ABI type via the
SolTypeassociated type. See the docs for sealedSolTypeEncodetrait for a table of Rust/ink! primitive types mapped to their equivalent Solidity ABI type. - Implementing the
to_sol_typemethod which defines how to convert (preferably via a borrow) from&selfto&Self::SolType(i.e. the Solidity ABI representation).
§Example
use ink_primitives::SolEncode;
// Example arbitrary type.
struct MyType {
size: u8,
status: bool,
}
// `SolEncode` implementation/mapping.
impl<'a> SolEncode<'a> for MyType {
// NOTE: Prefer reference based representation for better performance.
type SolType = (&'a u8, &'a bool);
fn to_sol_type(&'a self) -> Self::SolType {
(&self.size, &self.status)
}
}Provided Associated Constants§
Required Associated Types§
Sourcetype SolType: SolTypeEncode + SolTopicEncode
type SolType: SolTypeEncode + SolTopicEncode
Equivalent Solidity ABI type representation.
§Note
Prefer reference based representation for better performance.
Required Methods§
Sourcefn to_sol_type(&'a self) -> Self::SolType
fn to_sol_type(&'a self) -> Self::SolType
Converts from Self to Self::SolType via either a borrow (if possible), or
a possibly expensive conversion otherwise.
Provided Methods§
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.