pub trait SolDecode {
type SolType: SolTypeDecode;
const SOL_NAME: &'static str = <<Self::SolType as SolTypeDecode>::AlloyType as AlloySolType>::SOL_NAME;
// Required method
fn from_sol_type(value: Self::SolType) -> Self;
// Provided method
fn decode(data: &[u8]) -> Result<Self, Error>
where Self: Sized { ... }
}
Expand description
Maps an arbitrary Rust/ink! type to a Solidity ABI type equivalent for Solidity ABI decoding.
§Note
Implementing this trait entails:
- Declaring the equivalent Solidity ABI type via the
SolType
associated type. See the docs for sealedSolTypeDecode
trait for a table of Rust/ink! primitive types mapped to their equivalent Solidity ABI type. - Implementing the
from_sol_type
method which defines how to convert from the Solidity ABI representation (i.e.Self::SolType
) to this type.
§Example
use ink_primitives::SolDecode;
// Example arbitrary type.
struct MyType {
size: u8,
status: bool,
}
// `SolDecode` implementation/mapping.
impl SolDecode for MyType {
type SolType = (u8, bool);
fn from_sol_type(value: Self::SolType) -> Self {
Self {
size: value.0,
status: value.1,
}
}
}
Provided Associated Constants§
Required Associated Types§
Sourcetype SolType: SolTypeDecode
type SolType: SolTypeDecode
Equivalent Solidity ABI type representation.
Required Methods§
Sourcefn from_sol_type(value: Self::SolType) -> Self
fn from_sol_type(value: Self::SolType) -> Self
Converts to Self
from Self::SolType
.
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.