binary_cookies/sync/
cursor.rs1use std::{fs::File, io::Read};
2
3pub trait CookieCursor {
4 type Cursor<'a>: Read + 'a
5 where
6 Self: 'a;
7
8 fn cursor_at(&self, offset: u64) -> Self::Cursor<'_>;
9}
10
11impl CookieCursor for &[u8] {
12 type Cursor<'a>
13 = &'a [u8]
14 where
15 Self: 'a;
16
17 fn cursor_at(&self, offset: u64) -> Self::Cursor<'_> {
18 &self[offset as usize..]
19 }
20}
21
22impl CookieCursor for Vec<u8> {
23 type Cursor<'a>
24 = &'a [u8]
25 where
26 Self: 'a;
27
28 fn cursor_at(&self, offset: u64) -> Self::Cursor<'_> {
29 &self[offset as usize..]
30 }
31}
32
33impl CookieCursor for File {
34 type Cursor<'a>
35 = positioned_io::Cursor<&'a Self>
36 where
37 Self: 'a;
38
39 fn cursor_at(&self, offset: u64) -> Self::Cursor<'_> {
40 positioned_io::Cursor::new_pos(self, offset)
41 }
42}