Skip to main content

object_rainbow/
runtime_array.rs

1use crate::*;
2
3#[pod(no_copy, no_inline_output, no_parse, no_size, no_niche)]
4#[derive(ParseAsInline)]
5pub struct RuntimeArray<T>(pub Vec<T>);
6
7impl<T> Deref for RuntimeArray<T> {
8    type Target = Vec<T>;
9
10    fn deref(&self) -> &Self::Target {
11        &self.0
12    }
13}
14
15impl<T> DerefMut for RuntimeArray<T> {
16    fn deref_mut(&mut self) -> &mut Self::Target {
17        &mut self.0
18    }
19}
20
21impl<A> FromIterator<A> for RuntimeArray<A> {
22    fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self {
23        Self(iter.into_iter().collect())
24    }
25}
26
27/// Here we assume extra will match on re-parsing, which is a general requirement for correctness
28/// anyway.
29impl<T: InlineOutput> InlineOutput for RuntimeArray<T> {}
30
31impl<T: ParseInline<I::WithExtra<E>>, I: PointInput<Extra = (u64, E)>, E: 'static + Clone>
32    ParseInline<I> for RuntimeArray<T>
33{
34    fn parse_inline(input: &mut I) -> crate::Result<Self> {
35        let (n, extra) = input.extra().clone();
36        (0..n)
37            .map(|_| input.parse_inline_extra(extra.clone()))
38            .collect()
39    }
40}