git.delta.rocks / unique-network / refs/commits / 50ff12a1bcf4

difftreelog

feat Add impl AbiType+AbiRead+AbiWrite for Option<T>

Trubnikov Sergey2023-01-09parent: #0da35ba.patch.diff
in: master

1 file changed

modifiedcrates/evm-coder/src/abi/impls.rsdiffbeforeafterboth
259impl_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}
261
262//----- impls for Option -----
263impl<T: AbiType> AbiType for Option<T> {
264 const SIGNATURE: SignatureUnit = <(bool, T)>::SIGNATURE;
265
266 fn is_dynamic() -> bool {
267 <(bool, T)>::is_dynamic()
268 }
269
270 fn size() -> usize {
271 <(bool, T)>::size()
272 }
273}
274
275impl<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}
283
284impl<T> AbiRead for Option<T>
285where
286 Self: AbiType,
287 T: AbiRead + AbiType,
288{
289 fn abi_read(reader: &mut AbiReader) -> Result<Self>
290 where
291 Self: Sized,
292 {
293 let (status, value) = <(bool, T)>::abi_read(reader)?;
294 Ok(if status { Some(value) } else { None })
295 }
296}
261297