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
//! Sans-IO byte-range reading traits.
//!
//! Generic over a `Ctx` type that provides additional context for each read
//! (e.g. a volume filename). Defaults to `()` when no context is needed.
//!
//! # Examples
//!
//! A simple in-memory source:
//!
//! ```
//! use std::ops::Range;
//! use fskit::ReadAt;
//!
//! struct MemSource(Vec<u8>);
//!
//! impl ReadAt for MemSource {
//! fn read_at(&self, _ctx: &(), range: Range<u64>) -> std::io::Result<impl AsRef<[u8]>> {
//! Ok(&self.0[range.start as usize..range.end as usize])
//! }
//! }
//! ```
//!
//! A multi-volume source:
//!
//! ```
//! use std::collections::HashMap;
//! use std::ops::Range;
//! use fskit::ReadAt;
//!
//! struct MultiVolume {
//! volumes: HashMap<String, Vec<u8>>,
//! }
//!
//! impl ReadAt<String> for MultiVolume {
//! fn read_at(&self, volume: &String, range: Range<u64>) -> std::io::Result<impl AsRef<[u8]>> {
//! let data = self.volumes.get(volume)
//! .ok_or_else(|| std::io::Error::new(std::io::ErrorKind::NotFound, "volume not found"))?;
//! Ok(&data[range.start as usize..range.end as usize])
//! }
//! }
//! ```
use Range;
/// Synchronous byte-range read from a backing data source.
///
/// `Ctx` is additional context passed on each read. Defaults to `()`.
/// Async counterpart of [`ReadAt`].