difftreelog
feat Add impl AbiType+AbiRead+AbiWrite for Option<T>
in: master
1 file changed
crates/evm-coder/src/abi/impls.rsdiffbeforeafterboth259impl_tuples! {A B C D E F G H I}259impl_tuples! {A B C D E F G H I}260impl_tuples! {A B C D E F G H I J}260impl_tuples! {A B C D E F G H I J}261262//----- impls for Option -----263impl<T: AbiType> AbiType for Option<T> {264 const SIGNATURE: SignatureUnit = <(bool, T)>::SIGNATURE;265266 fn is_dynamic() -> bool {267 <(bool, T)>::is_dynamic()268 }269270 fn size() -> usize {271 <(bool, T)>::size()272 }273}274275impl<T: AbiWrite + AbiType + Default> AbiWrite for Option<T> {276 fn abi_write(&self, writer: &mut AbiWriter) {277 match self {278 Some(value) => (true, value).abi_write(writer),279 None => (true, T::default()).abi_write(writer),280 }281 }282}283284impl<T> AbiRead for Option<T>285where286 Self: AbiType,287 T: AbiRead + AbiType,288{289 fn abi_read(reader: &mut AbiReader) -> Result<Self>290 where291 Self: Sized,292 {293 let (status, value) = <(bool, T)>::abi_read(reader)?;294 Ok(if status { Some(value) } else { None })295 }296}261297