multiversx_sc_codec/multi/
top_en_multi.rsuse crate::{
DefaultErrorHandler, EncodeError, EncodeErrorHandler, TopEncode, TopEncodeMultiOutput,
};
pub trait TopEncodeMulti: Sized {
fn multi_encode<O>(&self, output: &mut O) -> Result<(), EncodeError>
where
O: TopEncodeMultiOutput,
{
self.multi_encode_or_handle_err(output, DefaultErrorHandler)
}
fn multi_encode_or_handle_err<O, H>(&self, output: &mut O, h: H) -> Result<(), H::HandledErr>
where
O: TopEncodeMultiOutput,
H: EncodeErrorHandler,
{
match self.multi_encode(output) {
Ok(()) => Ok(()),
Err(e) => Err(h.handle_error(e)),
}
}
}
impl<T> TopEncodeMulti for T
where
T: TopEncode,
{
fn multi_encode_or_handle_err<O, H>(&self, output: &mut O, h: H) -> Result<(), H::HandledErr>
where
O: TopEncodeMultiOutput,
H: EncodeErrorHandler,
{
output.push_single_value(self, h)
}
}
pub fn multi_encode_iter_or_handle_err<T, Iter, O, H>(
iterator: Iter,
output: &mut O,
h: H,
) -> Result<(), H::HandledErr>
where
T: TopEncodeMulti,
Iter: Iterator<Item = T>,
O: TopEncodeMultiOutput,
H: EncodeErrorHandler,
{
for item in iterator {
item.multi_encode_or_handle_err(output, h)?;
}
Ok(())
}