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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
use crate::traits::{FromPointerReader, FromPointerBuilder, ListIter, IndexMove};
use crate::private::layout::{ListReader, ListBuilder, PointerReader, PointerBuilder, Pointer};
use crate::Result;
#[derive(Clone, Copy)]
pub struct Owned<T> where T: for<'a> crate::traits::Owned<'a> {
marker: ::std::marker::PhantomData<T>,
}
impl<'a, T> crate::traits::Owned<'a> for Owned<T> where T: for<'b> crate::traits::Owned<'b> {
type Reader = Reader<'a, T>;
type Builder = Builder<'a, T>;
}
pub struct Reader<'a, T> where T: for<'b> crate::traits::Owned<'b> {
marker: ::std::marker::PhantomData<<T as crate::traits::Owned<'a>>::Reader>,
reader: ListReader<'a>
}
impl <'a, T> Reader<'a, T> where T: for<'b> crate::traits::Owned<'b> {
pub fn new<'b>(reader: ListReader<'b>) -> Reader<'b, T> {
Reader::<'b, T> { reader: reader, marker: ::std::marker::PhantomData }
}
pub fn len(&self) -> u32 { self.reader.len() }
pub fn iter(self) -> ListIter<Reader<'a, T>, Result<<T as crate::traits::Owned<'a>>::Reader>> {
ListIter::new(self, self.len())
}
}
impl <'a, T> Clone for Reader<'a, T> where T: for<'b> crate::traits::Owned<'b> {
fn clone(&self) -> Reader<'a, T> {
Reader { marker : self.marker, reader : self.reader }
}
}
impl <'a, T> Copy for Reader<'a, T> where T: for<'b> crate::traits::Owned<'b> {}
impl <'a, T> IndexMove<u32, Result<<T as crate::traits::Owned<'a>>::Reader>> for Reader<'a, T>
where T: for<'b> crate::traits::Owned<'b> {
fn index_move(&self, index : u32) -> Result<<T as crate::traits::Owned<'a>>::Reader> {
self.get(index)
}
}
impl <'a, T> FromPointerReader<'a> for Reader<'a, T> where T: for<'b> crate::traits::Owned<'b> {
fn get_from_pointer(reader: &PointerReader<'a>, default: Option<&'a [crate::Word]>) -> Result<Reader<'a, T>> {
Ok(Reader { reader: reader.get_list(Pointer, default)?,
marker: ::std::marker::PhantomData })
}
}
impl <'a, T> Reader<'a, T> where T: for<'b> crate::traits::Owned<'b> {
pub fn get(self, index: u32) -> Result<<T as crate::traits::Owned<'a>>::Reader> {
assert!(index < self.len());
FromPointerReader::get_from_pointer(&self.reader.get_pointer_element(index), None)
}
}
pub struct Builder<'a, T> where T: for<'b> crate::traits::Owned<'b> {
marker: ::std::marker::PhantomData<T>,
builder: ListBuilder<'a>
}
impl <'a, T> Builder<'a, T> where T: for<'b> crate::traits::Owned<'b> {
pub fn new(builder: ListBuilder<'a>) -> Builder<'a, T> {
Builder { builder: builder, marker: ::std::marker::PhantomData }
}
pub fn len(&self) -> u32 { self.builder.len() }
pub fn into_reader(self) -> Reader<'a, T> {
Reader { reader: self.builder.into_reader(), marker: ::std::marker::PhantomData }
}
}
impl <'a, T> Builder<'a, T> where T: for<'b> crate::traits::Owned<'b> {
pub fn init(self, index: u32, size: u32) -> <T as crate::traits::Owned<'a>>::Builder {
FromPointerBuilder::init_pointer(self.builder.get_pointer_element(index), size)
}
}
impl <'a, T> Builder<'a, T> where T: for<'b> crate::traits::Owned<'b> {
pub fn reborrow<'b>(&'b mut self) -> Builder<'b, T> {
Builder {builder: self.builder.borrow(), marker: ::std::marker::PhantomData}
}
}
impl <'a, T> FromPointerBuilder<'a> for Builder<'a, T> where T: for<'b> crate::traits::Owned<'b> {
fn init_pointer(builder: PointerBuilder<'a>, size : u32) -> Builder<'a, T> {
Builder {
marker: ::std::marker::PhantomData,
builder: builder.init_list(Pointer, size)
}
}
fn get_from_pointer(builder: PointerBuilder<'a>, default: Option<&'a [crate::Word]>) -> Result<Builder<'a, T>> {
Ok(Builder {
marker: ::std::marker::PhantomData,
builder: builder.get_list(Pointer, default)?
})
}
}
impl <'a, T> Builder<'a, T> where T: for<'b> crate::traits::Owned<'b> {
pub fn get(self, index: u32) -> Result<<T as crate::traits::Owned<'a>>::Builder> {
assert!(index < self.len());
FromPointerBuilder::get_from_pointer(self.builder.get_pointer_element(index), None)
}
}
impl <'a, T> crate::traits::SetPointerBuilder<Builder<'a, T>> for Reader<'a, T>
where T: for<'b> crate::traits::Owned<'b>
{
fn set_pointer_builder<'b>(pointer: crate::private::layout::PointerBuilder<'b>,
value: Reader<'a, T>,
canonicalize: bool) -> Result<()> {
pointer.set_list(&value.reader, canonicalize)
}
}
impl <'a, T> ::std::iter::IntoIterator for Reader<'a, T>
where T: for<'b> crate::traits::Owned<'b>
{
type Item = Result<<T as crate::traits::Owned<'a>>::Reader>;
type IntoIter = ListIter<Reader<'a, T>, Self::Item>;
fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}