@@ -8,13 +8,12 @@
Loading
8 8
    error::{PRes, PersyError},
9 9
    flush_checksum::{double_buffer_check, prepare_buffer_flush},
10 10
    id::{PersyId, RecRef},
11 -
    io::{read_u64, write_u64, ReadFormat, WriteFormat},
11 +
    io::{read_u64, write_u64, InfallibleRead, InfallibleReadFormat, InfallibleWrite, InfallibleWriteFormat},
12 12
    persy::exp_from_content_size,
13 13
};
14 14
use std::{
15 15
    collections::{hash_map::DefaultHasher, HashMap},
16 16
    hash::{Hash, Hasher},
17 -
    io::{Read, Write},
18 17
    str,
19 18
    sync::Arc,
20 19
    vec,
@@ -106,12 +105,12 @@
Loading
106 105
        let last = self.persistent_page;
107 106
        loop {
108 107
            let mut pag = allocator.load_page(page)?;
109 -
            let next = pag.read_u64()?;
108 +
            let next = pag.read_u64();
110 109
            let mut pos = SEGMENT_DATA_OFFSET;
111 110
            loop {
112 111
                pag.seek(pos)?;
113 -
                let data_page = pag.read_u64()?;
114 -
                let flag = pag.read_u8()?;
112 +
                let data_page = pag.read_u64();
113 +
                let flag = pag.read_u8();
115 114
                if entry_exits(flag) {
116 115
                    pages.push(data_page);
117 116
                }
@@ -153,17 +152,17 @@
Loading
153 152
    flags & FLAG_EXISTS == 1 && flags & FLAG_DELETED == 0
154 153
}
155 154
156 -
impl<T: ReadFormat + PageOps> SegmentPageRead for T {
155 +
impl<T: InfallibleRead + PageOps> SegmentPageRead for T {
157 156
    fn segment_read_entry(&mut self, segment_id: u32, pos: u32) -> PRes<Option<(u64, u16)>> {
158 157
        self.seek(SEGMENT_HASH_OFFSET)?;
159 -
        let persistent_id = self.read_u32()?;
158 +
        let persistent_id = self.read_u32();
160 159
        if persistent_id != segment_id {
161 160
            return Ok(None);
162 161
        }
163 162
        self.seek(pos)?;
164 -
        let record = self.read_u64()?;
165 -
        let flag = self.read_u8()?;
166 -
        let version = self.read_u16()?;
163 +
        let record = self.read_u64();
164 +
        let flag = self.read_u8();
165 +
        let version = self.read_u16();
167 166
        Ok(if !entry_exits(flag) || record == 0 {
168 167
            None
169 168
        } else {
@@ -172,12 +171,12 @@
Loading
172 171
    }
173 172
174 173
    fn segment_scan_all_entries(&mut self) -> PRes<(u64, Vec<(u32, bool)>)> {
175 -
        let next_page = self.read_u64()?;
174 +
        let next_page = self.read_u64();
176 175
        let mut pos = SEGMENT_DATA_OFFSET;
177 176
        let mut recs = Vec::new();
178 177
        loop {
179 178
            self.seek(pos + 8)?;
180 -
            let flag = self.read_u8()?;
179 +
            let flag = self.read_u8();
181 180
            recs.push((pos, flag & FLAG_EXISTS == 1));
182 181
            pos += ADDRESS_ENTRY_SIZE;
183 182
            if pos > ADDRESS_PAGE_SIZE - ADDRESS_ENTRY_SIZE {
@@ -188,12 +187,12 @@
Loading
188 187
    }
189 188
190 189
    fn segment_scan_entries(&mut self) -> PRes<(u64, Vec<u32>)> {
191 -
        let next_page = self.read_u64()?;
190 +
        let next_page = self.read_u64();
192 191
        let mut pos = SEGMENT_DATA_OFFSET;
193 192
        let mut recs = Vec::new();
194 193
        loop {
195 194
            self.seek(pos + 8)?;
196 -
            let flag = self.read_u8()?;
195 +
            let flag = self.read_u8();
197 196
            if entry_exits(flag) {
198 197
                recs.push(pos);
199 198
            }
@@ -210,7 +209,7 @@
Loading
210 209
        let mut pos = SEGMENT_DATA_OFFSET + (elements - 1) * ADDRESS_ENTRY_SIZE;
211 210
        loop {
212 211
            self.seek(pos + 8)?;
213 -
            let flag = self.read_u8()?;
212 +
            let flag = self.read_u8();
214 213
            if entry_exits(flag) {
215 214
                pos += ADDRESS_ENTRY_SIZE;
216 215
                break;
@@ -226,16 +225,16 @@
Loading
226 225
227 226
    fn get_next(&mut self) -> PRes<u64> {
228 227
        self.seek(0)?;
229 -
        self.read_u64().map_err(<_>::into)
228 +
        Ok(self.read_u64())
230 229
    }
231 230
232 231
    fn get_prev(&mut self) -> PRes<u64> {
233 232
        self.seek(8)?;
234 -
        self.read_u64().map_err(<_>::into)
233 +
        Ok(self.read_u64())
235 234
    }
236 235
    fn empty(&mut self) -> PRes<bool> {
237 236
        self.seek(SEGMENT_PAGE_DELETE_COUNT_OFFSET)?;
238 -
        Ok(self.read_u16()? as u32 == ADDRESS_PAGE_ENTRY_COUNT)
237 +
        Ok(self.read_u16() as u32 == ADDRESS_PAGE_ENTRY_COUNT)
239 238
    }
240 239
}
241 240
@@ -248,70 +247,70 @@
Loading
248 247
    }
249 248
}
250 249
251 -
impl<T: ReadFormat + WriteFormat + PageOps> SegmentPage for T {
250 +
impl<T: InfallibleRead + InfallibleWrite + PageOps> SegmentPage for T {
252 251
    fn segment_insert_entry(&mut self, segment_id: u32, pos: u32, record_page: u64) -> PRes<()> {
253 252
        debug_assert!(pos >= SEGMENT_DATA_OFFSET, "invalid page position {}", pos);
254 253
        self.seek(SEGMENT_HASH_OFFSET)?;
255 -
        let persistent_id = self.read_u32()?;
254 +
        let persistent_id = self.read_u32();
256 255
        if persistent_id != segment_id {
257 256
            return Err(PersyError::SegmentNotFound);
258 257
        }
259 258
        // TODO: In case of restore this may get a wrong value, so on restore should be
260 259
        // re-calculated from the persistent flags.
261 260
        self.seek(pos)?;
262 -
        self.write_u64(record_page)?;
263 -
        self.write_u8(FLAG_EXISTS)?;
264 -
        self.write_u16(1)?;
261 +
        self.write_u64(record_page);
262 +
        self.write_u8(FLAG_EXISTS);
263 +
        self.write_u16(1);
265 264
        Ok(())
266 265
    }
267 266
    fn segment_update_entry(&mut self, segment_id: u32, pos: u32, record_page: u64) -> PRes<()> {
268 267
        debug_assert!(pos >= SEGMENT_DATA_OFFSET);
269 268
        self.seek(SEGMENT_HASH_OFFSET)?;
270 -
        let persistent_id = self.read_u32()?;
269 +
        let persistent_id = self.read_u32();
271 270
        if persistent_id != segment_id {
272 271
            return Err(PersyError::RecordNotFound(PersyId(RecRef::new(self.get_index(), pos))));
273 272
        }
274 273
        self.seek(pos + 9)?;
275 -
        let version = self.read_u16()?;
274 +
        let version = self.read_u16();
276 275
        self.seek(pos)?;
277 -
        self.write_u64(record_page)?;
276 +
        self.write_u64(record_page);
278 277
        self.seek(pos + 9)?;
279 -
        self.write_u16(inc_version(version))?;
278 +
        self.write_u16(inc_version(version));
280 279
        Ok(())
281 280
    }
282 281
    fn segment_delete_entry(&mut self, segment_id: u32, pos: u32) -> PRes<bool> {
283 282
        debug_assert!(pos >= SEGMENT_DATA_OFFSET);
284 283
        self.seek(SEGMENT_HASH_OFFSET)?;
285 -
        let persistent_id = self.read_u32()?;
284 +
        let persistent_id = self.read_u32();
286 285
        if persistent_id != segment_id {
287 286
            return Err(PersyError::RecordNotFound(PersyId(RecRef::new(self.get_index(), pos))));
288 287
        }
289 288
        self.seek(SEGMENT_PAGE_DELETE_COUNT_OFFSET)?;
290 -
        let count = self.read_u16()? + 1;
289 +
        let count = self.read_u16() + 1;
291 290
        self.seek(SEGMENT_PAGE_DELETE_COUNT_OFFSET)?;
292 -
        self.write_u16(count)?;
291 +
        self.write_u16(count);
293 292
        self.seek(pos + 8)?;
294 -
        let flag = self.read_u8()?;
293 +
        let flag = self.read_u8();
295 294
        self.seek(pos + 8)?;
296 -
        self.write_u8(flag | FLAG_DELETED)?;
295 +
        self.write_u8(flag | FLAG_DELETED);
297 296
        Ok(count as u32 == ADDRESS_PAGE_ENTRY_COUNT)
298 297
    }
299 298
300 299
    fn set_segment_id(&mut self, id: u32) -> PRes<()> {
301 300
        self.seek(SEGMENT_HASH_OFFSET)?;
302 -
        self.write_u32(id)?;
301 +
        self.write_u32(id);
303 302
        Ok(())
304 303
    }
305 304
306 305
    fn set_next(&mut self, next: u64) -> PRes<()> {
307 306
        self.seek(0)?;
308 -
        self.write_u64(next)?;
307 +
        self.write_u64(next);
309 308
        Ok(())
310 309
    }
311 310
312 311
    fn set_prev(&mut self, prev: u64) -> PRes<()> {
313 312
        self.seek(8)?;
314 -
        self.write_u64(prev)?;
313 +
        self.write_u64(prev);
315 314
        Ok(())
316 315
    }
317 316
@@ -320,7 +319,7 @@
Loading
320 319
        let mut count = 0;
321 320
        loop {
322 321
            self.seek(pos + 8)?;
323 -
            let flag = self.read_u8()?;
322 +
            let flag = self.read_u8();
324 323
            if flag & FLAG_DELETED == FLAG_DELETED {
325 324
                count += 1;
326 325
            }
@@ -330,7 +329,7 @@
Loading
330 329
            }
331 330
        }
332 331
        self.seek(SEGMENT_PAGE_DELETE_COUNT_OFFSET)?;
333 -
        self.write_u8(count as u8)?;
332 +
        self.write_u8(count as u8);
334 333
        Ok(())
335 334
    }
336 335
}
@@ -365,8 +364,8 @@
Loading
365 364
        let last_flush;
366 365
        {
367 366
            let mut root = allocator.load_page(root_page)?;
368 -
            root.read_exact(&mut buffer_0)?;
369 -
            root.read_exact(&mut buffer_1)?;
367 +
            root.read_exact(&mut buffer_0);
368 +
            root.read_exact(&mut buffer_1);
370 369
            let (flush, first) = double_buffer_check(&buffer_0, &buffer_1);
371 370
            last_flush = flush;
372 371
            if first {
@@ -382,16 +381,16 @@
Loading
382 381
        if page_id != 0 {
383 382
            let mut page = allocator.load_page(page_id)?;
384 383
            loop {
385 -
                let flag = page.read_u8()?;
384 +
                let flag = page.read_u8();
386 385
                if flag == 1 {
387 -
                    let first_page = page.read_u64()?;
388 -
                    let persistent_page = page.read_u64()?;
389 -
                    let persistent_pos = page.read_u32()?;
390 -
                    let pers_hash = page.read_u32()?;
391 -
                    let name_size = page.read_u16()? as usize;
386 +
                    let first_page = page.read_u64();
387 +
                    let persistent_page = page.read_u64();
388 +
                    let persistent_pos = page.read_u32();
389 +
                    let pers_hash = page.read_u32();
390 +
                    let name_size = page.read_u16() as usize;
392 391
393 392
                    let mut slice: Vec<u8> = vec![0; name_size];
394 -
                    page.read_exact(&mut slice)?;
393 +
                    page.read_exact(&mut slice);
395 394
                    let name: String = str::from_utf8(&slice[0..name_size])?.into();
396 395
                    segments.insert(
397 396
                        pers_hash,
@@ -428,7 +427,7 @@
Loading
428 427
        write_u64(&mut buffer[0..8], 0);
429 428
        write_u64(&mut buffer[8..16], 0);
430 429
        prepare_buffer_flush(&mut buffer, 0);
431 -
        root.write_all(&buffer)?;
430 +
        root.write_all(&buffer);
432 431
        allocator.flush_page(root)?;
433 432
        Ok(())
434 433
    }
@@ -472,9 +471,9 @@
Loading
472 471
        );
473 472
        self.temp_segments.insert(segment_id, seg);
474 473
        self.temp_segments_id.insert(segment.to_string(), segment_id);
475 -
        allocated.write_u64(0)?;
476 -
        allocated.write_u64(0)?;
477 -
        allocated.write_u32(segment_id)?;
474 +
        allocated.write_u64(0);
475 +
        allocated.write_u64(0);
476 +
        allocated.write_u32(segment_id);
478 477
        allocator.flush_page(allocated)?;
479 478
        Ok((segment_id, allocated_id))
480 479
    }
@@ -558,15 +557,15 @@
Loading
558 557
    pub fn flush_segments(&mut self, allocator: &Allocator) -> PRes<()> {
559 558
        let mut buffer = Vec::<u8>::new();
560 559
        for segment in self.segments.values() {
561 -
            buffer.write_u8(1)?;
562 -
            buffer.write_u64(segment.first_page)?;
563 -
            buffer.write_u64(segment.persistent_page)?;
564 -
            buffer.write_u32(segment.persistent_pos)?;
565 -
            buffer.write_u32(segment.segment_id)?;
566 -
            buffer.write_u16(segment.name.len() as u16)?;
567 -
            buffer.write_all(segment.name.as_bytes())?;
568 -
        }
569 -
        buffer.write_u8(0)?;
560 +
            buffer.write_u8(1);
561 +
            buffer.write_u64(segment.first_page);
562 +
            buffer.write_u64(segment.persistent_page);
563 +
            buffer.write_u32(segment.persistent_pos);
564 +
            buffer.write_u32(segment.segment_id);
565 +
            buffer.write_u16(segment.name.len() as u16);
566 +
            buffer.write_all(segment.name.as_bytes());
567 +
        }
568 +
        buffer.write_u8(0);
570 569
        let exp = exp_from_content_size(buffer.len() as u64);
571 570
        let other_page_id = self.content_page;
572 571
        let mut content_page_id = self.other_page;
@@ -582,7 +581,7 @@
Loading
582 581
                page
583 582
            };
584 583
            content_page_id = content_page.get_index();
585 -
            content_page.write_all(&buffer)?;
584 +
            content_page.write_all(&buffer);
586 585
            allocator.flush_page(content_page)?;
587 586
        }
588 587
@@ -594,7 +593,7 @@
Loading
594 593
        {
595 594
            let mut root = allocator.write_page(self.root_page)?;
596 595
            root.seek(offset)?;
597 -
            root.write_all(&root_buffer)?;
596 +
            root.write_all(&root_buffer);
598 597
            allocator.flush_page(root)?;
599 598
        }
600 599
        self.content_page = content_page_id;

@@ -3,7 +3,6 @@
Loading
3 3
use std::{
4 4
    collections::HashMap,
5 5
    fs::File,
6 -
    io::Write,
7 6
    mem::replace,
8 7
    ops::{Bound, RangeBounds},
9 8
    path::Path,
@@ -29,7 +28,7 @@
Loading
29 28
    discref::{Device, DiscRef, MemRef, PageOps, PAGE_METADATA_SIZE},
30 29
    error::{PRes, PersyError},
31 30
    id::{IndexId, PersyId, SegmentId, ToIndexId, ToSegmentId},
32 -
    io::{ReadFormat, WriteFormat},
31 +
    io::{InfallibleReadFormat, InfallibleWrite, InfallibleWriteFormat},
33 32
    journal::{Journal, JournalId, JOURNAL_PAGE_EXP},
34 33
    record_scanner::{SegmentRawIter, SegmentSnapshotRawIter, TxSegmentRawIter},
35 34
    snapshot::{release_snapshot, EntryCase, SegmentSnapshop, SnapshotId, Snapshots},
@@ -195,12 +194,12 @@
Loading
195 194
        {
196 195
            let mut root = allocator.disc().load_page_raw(root_page, DEFAULT_PAGE_EXP)?;
197 196
            // Version of the disc format
198 -
            root.write_u16(0)?;
197 +
            root.write_u16(0);
199 198
            // Position of the start of address structure
200 -
            root.write_u64(address_page)?;
199 +
            root.write_u64(address_page);
201 200
            // Start of the Log data, if shutdown well this will be every time 0
202 -
            root.write_u64(journal_page)?;
203 -
            root.write_u64(allocator_page)?;
201 +
            root.write_u64(journal_page);
202 +
            root.write_u64(allocator_page);
204 203
            allocator.flush_page(root)?;
205 204
            // TODO: check this never go over the first page
206 205
        }
@@ -214,10 +213,10 @@
Loading
214 213
        let allocator_page;
215 214
        {
216 215
            let mut pg = disc.load_page_raw(0, DEFAULT_PAGE_EXP)?;
217 -
            pg.read_u16()?; //THIS NOW is 0 all the time
218 -
            address_page = pg.read_u64()?;
219 -
            journal_page = pg.read_u64()?;
220 -
            allocator_page = pg.read_u64()?;
216 +
            pg.read_u16(); //THIS NOW is 0 all the times
217 +
            address_page = pg.read_u64();
218 +
            journal_page = pg.read_u64();
219 +
            allocator_page = pg.read_u64();
221 220
        }
222 221
        let config = Arc::new(config);
223 222
        let allocator = Arc::new(Allocator::new(disc, &config, allocator_page)?);
@@ -439,10 +438,10 @@
Loading
439 438
        if let Some(new_page) = maybe_new_page {
440 439
            tx.add_new_segment_page(&self.journal, segment_id.id, new_page.new_page, new_page.previus_page)?;
441 440
        }
442 -
        pg.write_u64(len)?;
443 -
        pg.write_u64(rec_ref.page)?;
444 -
        pg.write_u32(rec_ref.pos)?;
445 -
        pg.write_all(rec)?;
441 +
        pg.write_u64(len);
442 +
        pg.write_u64(rec_ref.page);
443 +
        pg.write_u32(rec_ref.pos);
444 +
        pg.write_all(rec);
446 445
        allocator.flush_page(pg)?;
447 446
        Ok(rec_ref)
448 447
    }
@@ -487,9 +486,9 @@
Loading
487 486
        F: Fn(&[u8]) -> T,
488 487
    {
489 488
        if let Some(mut pg) = self.allocator.load_page_not_free(page)? {
490 -
            let len = pg.read_u64()?;
491 -
            let page = pg.read_u64()?;
492 -
            let pos = pg.read_u32()?;
489 +
            let len = pg.read_u64();
490 +
            let page = pg.read_u64();
491 +
            let pos = pg.read_u32();
493 492
            if page == match_id.page && pos == match_id.pos {
494 493
                Ok(Some(f(pg.slice(len as usize))))
495 494
            } else {
@@ -637,10 +636,10 @@
Loading
637 636
            let mut pg = allocator.allocate(allocation_exp)?;
638 637
            let page = pg.get_index();
639 638
            tx.add_update(journal, segment, &rec_ref, page, version)?;
640 -
            pg.write_u64(len as u64)?;
641 -
            pg.write_u64(rec_ref.page)?;
642 -
            pg.write_u32(rec_ref.pos)?;
643 -
            pg.write_all(rec)?;
639 +
            pg.write_u64(len as u64);
640 +
            pg.write_u64(rec_ref.page);
641 +
            pg.write_u32(rec_ref.pos);
642 +
            pg.write_all(rec);
644 643
            allocator.flush_page(pg)
645 644
        } else {
646 645
            Err(PersyError::RecordNotFound(PersyId(rec_ref.clone())))

@@ -6,18 +6,13 @@
Loading
6 6
        keeper::{Extractor, IndexSegmentKeeper, IndexSegmentKeeperTx},
7 7
        serialization::IndexSerialization,
8 8
    },
9 -
    io::{ReadFormat, WriteFormat},
9 +
    io::{InfallibleRead, InfallibleReadFormat, InfallibleWrite, InfallibleWriteFormat},
10 10
    locks::RwLockManager,
11 11
    persy::PersyImpl,
12 12
    snapshot::SnapshotId,
13 13
    transaction::Transaction,
14 14
};
15 -
use std::{
16 -
    fmt::Display,
17 -
    io::{Cursor, Read, Write},
18 -
    str,
19 -
    sync::Arc,
20 -
};
15 +
use std::{fmt::Display, io::Cursor, str, sync::Arc};
21 16
22 17
use data_encoding::BASE64URL_NOPAD;
23 18
@@ -219,35 +214,35 @@
Loading
219 214
}
220 215
221 216
impl IndexConfig {
222 -
    fn serialize(&self, w: &mut dyn Write) -> PRes<()> {
217 +
    fn serialize(&self, w: &mut dyn InfallibleWrite) -> PRes<()> {
223 218
        if let Some(ref root) = self.root {
224 -
            w.write_u64(root.page)?;
225 -
            w.write_u32(root.pos)?;
219 +
            w.write_u64(root.page);
220 +
            w.write_u32(root.pos);
226 221
        } else {
227 -
            w.write_u64(0)?;
228 -
            w.write_u32(0)?;
222 +
            w.write_u64(0);
223 +
            w.write_u32(0);
229 224
        }
230 -
        w.write_u8(self.key_type)?;
231 -
        w.write_u8(self.value_type)?;
232 -
        w.write_u32(self.page_min as u32)?;
233 -
        w.write_u32(self.page_max as u32)?;
234 -
        w.write_u8(self.value_mode.to_u8())?;
235 -
        w.write_u16(self.name.len() as u16)?;
236 -
        w.write_all(self.name.as_bytes())?;
225 +
        w.write_u8(self.key_type);
226 +
        w.write_u8(self.value_type);
227 +
        w.write_u32(self.page_min as u32);
228 +
        w.write_u32(self.page_max as u32);
229 +
        w.write_u8(self.value_mode.to_u8());
230 +
        w.write_u16(self.name.len() as u16);
231 +
        w.write_all(self.name.as_bytes());
237 232
        Ok(())
238 233
    }
239 -
    fn deserialize(r: &mut dyn Read) -> PRes<IndexConfig> {
240 -
        let index_root_page = r.read_u64()?;
241 -
        let index_root_pos = r.read_u32()?;
242 -
        let key_type = r.read_u8()?;
243 -
        let value_type = r.read_u8()?;
244 -
        let page_min = r.read_u32()? as usize;
245 -
        let page_max = r.read_u32()? as usize;
246 -
        let value_mode = ValueMode::from(r.read_u8()?);
234 +
    fn deserialize(r: &mut dyn InfallibleRead) -> PRes<IndexConfig> {
235 +
        let index_root_page = r.read_u64();
236 +
        let index_root_pos = r.read_u32();
237 +
        let key_type = r.read_u8();
238 +
        let value_type = r.read_u8();
239 +
        let page_min = r.read_u32() as usize;
240 +
        let page_max = r.read_u32() as usize;
241 +
        let value_mode = ValueMode::from(r.read_u8());
247 242
248 -
        let name_size = r.read_u16()? as usize;
243 +
        let name_size = r.read_u16() as usize;
249 244
        let mut slice: Vec<u8> = vec![0; name_size];
250 -
        r.read_exact(&mut slice)?;
245 +
        r.read_exact(&mut slice);
251 246
        let name: String = str::from_utf8(&slice[0..name_size])?.into();
252 247
        let root = if index_root_page != 0 && index_root_pos != 0 {
253 248
            Some(RecRef::new(index_root_page, index_root_pos))
@@ -480,7 +475,7 @@
Loading
480 475
        };
481 476
482 477
        let mut buff = Vec::new();
483 -
        cfg.serialize(&mut Cursor::new(&mut buff)).expect("serialization works");
478 +
        cfg.serialize(&mut buff).expect("serialization works");
484 479
        let read = IndexConfig::deserialize(&mut Cursor::new(&mut buff)).expect("deserialization works");
485 480
        assert_eq!(cfg, read);
486 481
    }

@@ -2,11 +2,11 @@
Loading
2 2
use byteorder::{BigEndian, ByteOrder, ReadBytesExt, WriteBytesExt};
3 3
use std::io::{Cursor, Read, Write};
4 4
5 -
pub(crate) trait InfallibleRead {
5 +
pub trait InfallibleRead {
6 6
    fn read_exact(&mut self, buf: &mut [u8]);
7 7
}
8 8
9 -
pub(crate) trait InfallibleWrite {
9 +
pub trait InfallibleWrite {
10 10
    fn write_all(&mut self, buf: &[u8]);
11 11
}
12 12

@@ -6,9 +6,9 @@
Loading
6 6
        keeper::Container,
7 7
        nodes::{Leaf, LeafEntry, Node, NodeRef, Nodes, Value},
8 8
    },
9 -
    io::{ReadFormat, WriteFormat},
9 +
    io::{InfallibleRead, InfallibleReadFormat, InfallibleWrite, InfallibleWriteFormat},
10 10
};
11 -
use std::io::{Cursor, Read, Write};
11 +
use std::io::Cursor;
12 12
13 13
macro_rules! impl_index_type {
14 14
    ($t:ty, $v:expr,$v1:ident,$w:ty) => {
@@ -41,27 +41,27 @@
Loading
41 41
impl_index_type!(ByteVec, 16, BYTEVEC, ByteVec);
42 42
43 43
pub trait IndexSerialization: Sized {
44 -
    fn serialize(&self, buffer: &mut dyn Write) -> PRes<()>;
45 -
    fn deserialize(value: &mut dyn Read) -> PRes<Self>;
44 +
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()>;
45 +
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self>;
46 46
}
47 47
48 48
pub fn deserialize<K: IndexType, V: IndexType>(value: &[u8]) -> PRes<Node<K, V>> {
49 49
    let mut reader = Cursor::new(value);
50 -
    let t = reader.read_u8()?;
50 +
    let t = reader.read_u8();
51 51
    match t {
52 52
        1 => {
53 -
            let prev = if reader.read_u8()? == 1 {
53 +
            let prev = if reader.read_u8() == 1 {
54 54
                Some(K::deserialize(&mut reader)?)
55 55
            } else {
56 56
                None
57 57
            };
58 -
            let size = reader.read_u32()?;
58 +
            let size = reader.read_u32();
59 59
            let mut entries = Vec::with_capacity(size as usize);
60 60
            for _ in 0..size {
61 61
                let key = K::deserialize(&mut reader)?;
62 -
                let value_type = reader.read_u8()?;
62 +
                let value_type = reader.read_u8();
63 63
                if value_type == 1 {
64 -
                    let val_size = reader.read_u32()?;
64 +
                    let val_size = reader.read_u32();
65 65
                    let mut value = Vec::with_capacity(val_size as usize);
66 66
                    for _ in 0..val_size {
67 67
                        value.push(V::deserialize(&mut reader)?);
@@ -78,7 +78,7 @@
Loading
78 78
                    });
79 79
                }
80 80
            }
81 -
            let next = if reader.read_u8()? == 1 {
81 +
            let next = if reader.read_u8() == 1 {
82 82
                Some(K::deserialize(&mut reader)?)
83 83
            } else {
84 84
                None
@@ -86,25 +86,25 @@
Loading
86 86
            Ok(Node::LEAF(Leaf { entries, prev, next }))
87 87
        }
88 88
        2 => {
89 -
            let prev = if reader.read_u8()? == 1 {
89 +
            let prev = if reader.read_u8() == 1 {
90 90
                Some(K::deserialize(&mut reader)?)
91 91
            } else {
92 92
                None
93 93
            };
94 -
            let size = reader.read_u32()?;
94 +
            let size = reader.read_u32();
95 95
            let mut keys = Vec::with_capacity(size as usize);
96 96
            for _ in 0..size {
97 97
                let key = K::deserialize(&mut reader)?;
98 98
                keys.push(key);
99 99
            }
100 -
            let size = reader.read_u32()?;
100 +
            let size = reader.read_u32();
101 101
            let mut pointers = Vec::with_capacity(size as usize);
102 102
            for _ in 0..size {
103 -
                let page = reader.read_u64()?;
104 -
                let pos = reader.read_u32()?;
103 +
                let page = reader.read_u64();
104 +
                let pos = reader.read_u32();
105 105
                pointers.push(RecRef::new(page, pos));
106 106
            }
107 -
            let next = if reader.read_u8()? == 1 {
107 +
            let next = if reader.read_u8() == 1 {
108 108
                Some(K::deserialize(&mut reader)?)
109 109
            } else {
110 110
                None
@@ -124,8 +124,8 @@
Loading
124 124
    let mut dest = Vec::new();
125 125
126 126
    let write_page_and_pos = |dest: &mut Vec<u8>, page, pos| -> PRes<()> {
127 -
        dest.write_u64(page)?;
128 -
        dest.write_u32(pos)?;
127 +
        dest.write_u64(page);
128 +
        dest.write_u32(pos);
129 129
        Ok(())
130 130
    };
131 131
@@ -140,58 +140,58 @@
Loading
140 140
141 141
    match node {
142 142
        Node::LEAF(leaf) => {
143 -
            dest.write_u8(1)?;
143 +
            dest.write_u8(1);
144 144
            if let Some(pk) = &leaf.prev {
145 -
                dest.write_u8(1)?;
145 +
                dest.write_u8(1);
146 146
                pk.serialize(&mut dest)?;
147 147
            } else {
148 -
                dest.write_u8(0)?;
148 +
                dest.write_u8(0);
149 149
            }
150 -
            dest.write_u32(leaf.entries.len() as u32)?;
150 +
            dest.write_u32(leaf.entries.len() as u32);
151 151
            for entry in &leaf.entries {
152 152
                entry.key.serialize(&mut dest)?;
153 153
                match &entry.value {
154 154
                    Value::CLUSTER(cluster) => {
155 -
                        dest.write_u8(1)?;
156 -
                        dest.write_u32(cluster.len() as u32)?;
155 +
                        dest.write_u8(1);
156 +
                        dest.write_u32(cluster.len() as u32);
157 157
                        for val in cluster {
158 158
                            val.serialize(&mut dest)?;
159 159
                        }
160 160
                    }
161 161
                    Value::SINGLE(val) => {
162 -
                        dest.write_u8(2)?;
162 +
                        dest.write_u8(2);
163 163
                        val.serialize(&mut dest)?;
164 164
                    }
165 165
                }
166 166
            }
167 167
            if let Some(pk) = &leaf.next {
168 -
                dest.write_u8(1)?;
168 +
                dest.write_u8(1);
169 169
                pk.serialize(&mut dest)?;
170 170
            } else {
171 -
                dest.write_u8(0)?;
171 +
                dest.write_u8(0);
172 172
            }
173 173
        }
174 174
        Node::NODE(node) => {
175 -
            dest.write_u8(2)?;
175 +
            dest.write_u8(2);
176 176
            if let Some(pk) = &node.prev {
177 -
                dest.write_u8(1)?;
177 +
                dest.write_u8(1);
178 178
                pk.serialize(&mut dest)?;
179 179
            } else {
180 -
                dest.write_u8(0)?;
180 +
                dest.write_u8(0);
181 181
            }
182 -
            dest.write_u32(node.keys.len() as u32)?;
182 +
            dest.write_u32(node.keys.len() as u32);
183 183
            for k in &node.keys {
184 184
                k.serialize(&mut dest)?;
185 185
            }
186 -
            dest.write_u32(node.pointers.len() as u32)?;
186 +
            dest.write_u32(node.pointers.len() as u32);
187 187
            for p in &node.pointers {
188 188
                write_opt_leafptr(&mut dest, Some(p))?;
189 189
            }
190 190
            if let Some(pk) = &node.next {
191 -
                dest.write_u8(1)?;
191 +
                dest.write_u8(1);
192 192
                pk.serialize(&mut dest)?;
193 193
            } else {
194 -
                dest.write_u8(0)?;
194 +
                dest.write_u8(0);
195 195
            }
196 196
        }
197 197
    }
@@ -199,150 +199,163 @@
Loading
199 199
}
200 200
201 201
impl IndexSerialization for u8 {
202 -
    fn serialize(&self, buffer: &mut dyn Write) -> PRes<()> {
203 -
        buffer.write_u8(*self).map_err(PersyError::from)
202 +
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
203 +
        buffer.write_u8(*self);
204 +
        Ok(())
204 205
    }
205 -
    fn deserialize(value: &mut dyn Read) -> PRes<Self> {
206 -
        value.read_u8().map_err(PersyError::from)
206 +
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
207 +
        Ok(value.read_u8())
207 208
    }
208 209
}
209 210
210 211
impl IndexSerialization for u16 {
211 -
    fn serialize(&self, buffer: &mut dyn Write) -> PRes<()> {
212 -
        buffer.write_u16(*self).map_err(PersyError::from)
212 +
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
213 +
        buffer.write_u16(*self);
214 +
        Ok(())
213 215
    }
214 -
    fn deserialize(value: &mut dyn Read) -> PRes<Self> {
215 -
        value.read_u16().map_err(PersyError::from)
216 +
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
217 +
        Ok(value.read_u16())
216 218
    }
217 219
}
218 220
219 221
impl IndexSerialization for u32 {
220 -
    fn serialize(&self, buffer: &mut dyn Write) -> PRes<()> {
221 -
        buffer.write_u32(*self).map_err(PersyError::from)
222 +
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
223 +
        buffer.write_u32(*self);
224 +
        Ok(())
222 225
    }
223 -
    fn deserialize(value: &mut dyn Read) -> PRes<Self> {
224 -
        value.read_u32().map_err(PersyError::from)
226 +
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
227 +
        Ok(value.read_u32())
225 228
    }
226 229
}
227 230
228 231
impl IndexSerialization for u64 {
229 -
    fn serialize(&self, buffer: &mut dyn Write) -> PRes<()> {
230 -
        buffer.write_u64(*self).map_err(PersyError::from)
232 +
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
233 +
        buffer.write_u64(*self);
234 +
        Ok(())
231 235
    }
232 -
    fn deserialize(value: &mut dyn Read) -> PRes<Self> {
233 -
        value.read_u64().map_err(PersyError::from)
236 +
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
237 +
        Ok(value.read_u64())
234 238
    }
235 239
}
236 240
237 241
impl IndexSerialization for u128 {
238 -
    fn serialize(&self, buffer: &mut dyn Write) -> PRes<()> {
239 -
        buffer.write_u128(*self).map_err(PersyError::from)
242 +
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
243 +
        buffer.write_u128(*self);
244 +
        Ok(())
240 245
    }
241 -
    fn deserialize(value: &mut dyn Read) -> PRes<Self> {
242 -
        value.read_u128().map_err(PersyError::from)
246 +
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
247 +
        Ok(value.read_u128())
243 248
    }
244 249
}
245 250
246 251
impl IndexSerialization for i8 {
247 -
    fn serialize(&self, buffer: &mut dyn Write) -> PRes<()> {
248 -
        buffer.write_i8(*self).map_err(PersyError::from)
252 +
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
253 +
        buffer.write_i8(*self);
254 +
        Ok(())
249 255
    }
250 -
    fn deserialize(value: &mut dyn Read) -> PRes<Self> {
251 -
        value.read_i8().map_err(PersyError::from)
256 +
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
257 +
        Ok(value.read_i8())
252 258
    }
253 259
}
254 260
255 261
impl IndexSerialization for i16 {
256 -
    fn serialize(&self, buffer: &mut dyn Write) -> PRes<()> {
257 -
        buffer.write_i16(*self).map_err(PersyError::from)
262 +
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
263 +
        buffer.write_i16(*self);
264 +
        Ok(())
258 265
    }
259 -
    fn deserialize(value: &mut dyn Read) -> PRes<Self> {
260 -
        value.read_i16().map_err(PersyError::from)
266 +
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
267 +
        Ok(value.read_i16())
261 268
    }
262 269
}
263 270
264 271
impl IndexSerialization for i32 {
265 -
    fn serialize(&self, buffer: &mut dyn Write) -> PRes<()> {
266 -
        buffer.write_i32(*self).map_err(PersyError::from)
272 +
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
273 +
        buffer.write_i32(*self);
274 +
        Ok(())
267 275
    }
268 -
    fn deserialize(value: &mut dyn Read) -> PRes<Self> {
269 -
        value.read_i32().map_err(PersyError::from)
276 +
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
277 +
        Ok(value.read_i32())
270 278
    }
271 279
}
272 280
273 281
impl IndexSerialization for i64 {
274 -
    fn serialize(&self, buffer: &mut dyn Write) -> PRes<()> {
275 -
        buffer.write_i64(*self).map_err(PersyError::from)
282 +
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
283 +
        buffer.write_i64(*self);
284 +
        Ok(())
276 285
    }
277 -
    fn deserialize(value: &mut dyn Read) -> PRes<Self> {
278 -
        value.read_i64().map_err(PersyError::from)
286 +
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
287 +
        Ok(value.read_i64())
279 288
    }
280 289
}
281 290
282 291
impl IndexSerialization for i128 {
283 -
    fn serialize(&self, buffer: &mut dyn Write) -> PRes<()> {
284 -
        buffer.write_i128(*self).map_err(PersyError::from)
292 +
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
293 +
        buffer.write_i128(*self);
294 +
        Ok(())
285 295
    }
286 -
    fn deserialize(value: &mut dyn Read) -> PRes<Self> {
287 -
        value.read_i128().map_err(PersyError::from)
296 +
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
297 +
        Ok(value.read_i128())
288 298
    }
289 299
}
290 300
291 301
impl IndexSerialization for f32 {
292 -
    fn serialize(&self, buffer: &mut dyn Write) -> PRes<()> {
293 -
        buffer.write_f32(*self).map_err(PersyError::from)
302 +
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
303 +
        buffer.write_f32(*self);
304 +
        Ok(())
294 305
    }
295 -
    fn deserialize(value: &mut dyn Read) -> PRes<Self> {
296 -
        value.read_f32().map_err(PersyError::from)
306 +
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
307 +
        Ok(value.read_f32())
297 308
    }
298 309
}
299 310
300 311
impl IndexSerialization for f64 {
301 -
    fn serialize(&self, buffer: &mut dyn Write) -> PRes<()> {
302 -
        buffer.write_f64(*self).map_err(PersyError::from)
312 +
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
313 +
        buffer.write_f64(*self);
314 +
        Ok(())
303 315
    }
304 -
    fn deserialize(value: &mut dyn Read) -> PRes<Self> {
305 -
        value.read_f64().map_err(PersyError::from)
316 +
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
317 +
        Ok(value.read_f64())
306 318
    }
307 319
}
308 320
309 321
impl IndexSerialization for PersyId {
310 -
    fn serialize(&self, buffer: &mut dyn Write) -> PRes<()> {
311 -
        buffer.write_u64(self.0.page)?;
312 -
        buffer.write_u32(self.0.pos)?;
322 +
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
323 +
        buffer.write_u64(self.0.page);
324 +
        buffer.write_u32(self.0.pos);
313 325
        Ok(())
314 326
    }
315 -
    fn deserialize(value: &mut dyn Read) -> PRes<Self> {
316 -
        let page = value.read_u64()?;
317 -
        let pos = value.read_u32()?;
327 +
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
328 +
        let page = value.read_u64();
329 +
        let pos = value.read_u32();
318 330
        Ok(PersyId(RecRef::new(page, pos)))
319 331
    }
320 332
}
321 333
322 334
impl IndexSerialization for String {
323 -
    fn serialize(&self, buffer: &mut dyn Write) -> PRes<()> {
324 -
        buffer.write_u16(self.len() as u16)?;
325 -
        buffer.write_all(self.as_bytes())?;
335 +
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
336 +
        buffer.write_u16(self.len() as u16);
337 +
        buffer.write_all(self.as_bytes());
326 338
        Ok(())
327 339
    }
328 -
    fn deserialize(value: &mut dyn Read) -> PRes<Self> {
329 -
        let string_size = value.read_u16()?;
330 -
        let mut string = String::with_capacity(string_size as usize);
331 -
        value.take(u64::from(string_size)).read_to_string(&mut string)?;
340 +
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
341 +
        let string_size = value.read_u16();
342 +
        let mut buff = vec![0; string_size as usize];
343 +
        value.read_exact(&mut buff);
344 +
        let string = String::from_utf8(buff).map_err(|e| PersyError::DecodingUtf8(e.utf8_error()))?;
332 345
        Ok(string)
333 346
    }
334 347
}
335 348
336 349
impl IndexSerialization for ByteVec {
337 -
    fn serialize(&self, buffer: &mut dyn Write) -> PRes<()> {
338 -
        buffer.write_u16(self.0.len() as u16)?;
339 -
        buffer.write_all(self.0.as_slice())?;
350 +
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
351 +
        buffer.write_u16(self.0.len() as u16);
352 +
        buffer.write_all(self.0.as_slice());
340 353
        Ok(())
341 354
    }
342 -
    fn deserialize(value: &mut dyn Read) -> PRes<Self> {
343 -
        let vec_size = value.read_u16()?;
344 -
        let mut slice: Vec<u8> = Vec::new();
345 -
        value.take(u64::from(vec_size)).read_to_end(&mut slice)?;
355 +
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
356 +
        let vec_size = value.read_u16();
357 +
        let mut slice: Vec<u8> = vec![0; vec_size as usize];
358 +
        value.read_exact(&mut slice);
346 359
        Ok(ByteVec(slice))
347 360
    }
348 361
}
Files Coverage
src 93.07%
tests 98.56%
Project Totals (29 files) 94.08%
Notifications are pending CI completion. Waiting for GitLab's status webhook to queue notifications. Push notifications now.
1
coverage:
2
  status:
3
    project:
4
      default:
5
        target: 80%
6
        threshold: 1.0%
7
    patch: off
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading