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
// =============================================================================
// Copyright (c) 2025 - 2026 Haixing Hu.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0.
// =============================================================================
//! Provider session for offset-based reads from one opened object.
use crateFsResult;
/// Reads bytes at explicit offsets from the object opened by the provider.
/// Implementations must keep using that object and may return short reads.
/// Each call is independent of previous offsets. On `Err`, the output buffer
/// may contain partial bytes and must not be treated as a complete result.
///
/// # Examples
///
/// ```
/// use qubit_fs::spi::RandomAccessReadSession;
/// use qubit_fs::FsResult;
///
/// struct Bytes(Vec<u8>);
/// impl RandomAccessReadSession for Bytes {
/// fn read_at(&mut self, offset: u64, output: &mut [u8]) -> FsResult<usize> {
/// let start = usize::try_from(offset).unwrap_or(usize::MAX);
/// let Some(remaining) = self.0.get(start..) else { return Ok(0); };
/// let count = output.len().min(remaining.len());
/// output[..count].copy_from_slice(&remaining[..count]);
/// Ok(count)
/// }
/// }
/// let mut session = Bytes(b"abc".to_vec());
/// let mut sample = [0; 4];
/// assert_eq!(2, session.read_at(1, &mut sample).unwrap()); // short read
/// assert_eq!(0, session.read_at(3, &mut sample).unwrap()); // EOF
/// ```