use crate::codec::{DecodeError, DecodeErrorHandler, TopDecodeMultiInput}; use crate::{ api::{ErrorApi, ManagedTypeApi}, types::{ManagedBuffer, ManagedVec}, }; pub struct ManagedResultArgLoader where A: ManagedTypeApi + ErrorApi, { data: ManagedVec>, data_len: usize, next_index: usize, } impl ManagedResultArgLoader where A: ManagedTypeApi + ErrorApi, { pub fn new(data: ManagedVec>) -> Self { let data_len = data.len(); ManagedResultArgLoader { data, data_len, next_index: 0, } } } impl TopDecodeMultiInput for ManagedResultArgLoader where A: ManagedTypeApi + ErrorApi, { type ValueInput = ManagedBuffer; fn has_next(&self) -> bool { self.next_index < self.data_len } fn next_value_input(&mut self, h: H) -> Result where H: DecodeErrorHandler, { if let Some(buffer) = self.data.try_get(self.next_index) { self.next_index += 1; Ok((*buffer).clone()) } else { Err(h.handle_error(DecodeError::MULTI_TOO_FEW_ARGS)) } } }