pub trait SolEncode<'a> {
type SolType: SolTypeEncode;
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 method
fn encode(&'a self) -> Vec<u8> ⓘ { ... }
}
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
SolType
associated type. See the docs for sealedSolTypeEncode
trait for a table of Rust/ink! primitive types mapped to their equivalent Solidity ABI type. - Implementing the
to_sol_type
method which defines how to convert (preferably via a borrow) from&self
to&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
type SolType: SolTypeEncode
Equivalent Solidity ABI type representation.
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.