1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use crate::{
api::{ErrorApi, ManagedTypeApi},
err_msg,
types::{ManagedBuffer, ManagedType, ManagedVec},
DynArgInput,
};
pub struct ManagedResultArgLoader<A>
where
A: ManagedTypeApi + ErrorApi,
{
data: ManagedVec<A, ManagedBuffer<A>>,
data_len: usize,
next_index: usize,
}
impl<A> ManagedResultArgLoader<A>
where
A: ManagedTypeApi + ErrorApi,
{
pub fn new(data: ManagedVec<A, ManagedBuffer<A>>) -> Self {
let data_len = data.len();
ManagedResultArgLoader {
data,
data_len,
next_index: 0,
}
}
}
impl<A> DynArgInput for ManagedResultArgLoader<A>
where
A: ManagedTypeApi + ErrorApi,
{
type ItemInput = ManagedBuffer<A>;
type ErrorApi = A;
#[inline]
fn dyn_arg_vm_api(&self) -> Self::ErrorApi {
self.data.type_manager()
}
#[inline]
fn has_next(&self) -> bool {
self.next_index < self.data_len
}
fn next_arg_input(&mut self) -> Self::ItemInput {
if let Some(buffer) = self.data.get(self.next_index) {
self.next_index += 1;
buffer
} else {
self.dyn_arg_vm_api()
.signal_error(err_msg::ARG_WRONG_NUMBER)
}
}
}