use crate::types::{Call, Param};
#[derive(Default)]
pub struct Batch {
calls: Vec<Call>,
}
impl Batch {
pub fn raw(&mut self, method: String, params: Vec<Param>) {
self.calls.push((method, params));
}
pub fn iter(&self) -> BatchIter<'_> {
BatchIter {
batch: self,
index: 0,
}
}
}
impl std::iter::IntoIterator for Batch {
type Item = (String, Vec<Param>);
type IntoIter = std::vec::IntoIter<Self::Item>;
fn into_iter(self) -> Self::IntoIter {
self.calls.into_iter()
}
}
pub struct BatchIter<'a> {
batch: &'a Batch,
index: usize,
}
impl<'a> std::iter::Iterator for BatchIter<'a> {
type Item = &'a (String, Vec<Param>);
fn next(&mut self) -> Option<Self::Item> {
let val = self.batch.calls.get(self.index);
self.index += 1;
val
}
}