pub trait SolDecode: Sized {
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) -> Result<Self, Error>;
// Provided method
fn decode(data: &[u8]) -> Result<Self, Error> { ... }
}
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::{
sol::Error,
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) -> Result<Self, Error> {
Ok(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) -> Result<Self, Error>
fn from_sol_type(value: Self::SolType) -> Result<Self, Error>
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.