Struct seq_data_file::SeqDataReaderSeek

source ·
pub struct SeqDataReaderSeek<Format: SeqDataFormat> { /* private fields */ }
Expand description

Seq Data Reader with seek

Implementations§

source§

impl<Format: SeqDataFormat> SeqDataReaderSeek<Format>

source

pub fn open<P: AsRef<Path>>(path: P) -> Result<(Self, Vec<u8>)>

Open a new Seq Data seeker

Examples found in repository?
examples/run.rs (line 73)
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
fn run_writer_reader<H: SeqDataFormat>(sdf_file: &Path) {
    {
        let header = vec![0x90; H::HEADER_SIZE];
        let mut sdf = SeqDataWriter::<H>::create(&sdf_file, &header).unwrap();
        sdf.append(DATA1).unwrap();
        sdf.append(DATA2).unwrap();
        sdf.append(DATA3).unwrap();
    }

    let mut pos = Vec::new();
    {
        let (mut sdf, _header) = SeqDataReader::<H>::open(&sdf_file).unwrap();
        let (p1, r1) = sdf.next().unwrap().unwrap();
        let (p2, r2) = sdf.next().unwrap().unwrap();
        let (p3, r3) = sdf.next().unwrap().unwrap();

        pos.push(p1);
        pos.push(p2);
        pos.push(p3);

        assert_eq!(p1, 0);
        assert_eq!(r1, DATA1);

        assert_eq!(p2, 4 + DATA1.len() as u64);
        assert_eq!(r2, DATA2);

        assert_eq!(p3, 4 * 2 + DATA1.len() as u64 + DATA2.len() as u64);
        assert_eq!(r3, DATA3);

        if let Some(x) = sdf.next() {
            panic!("more data than expected {:?}", x)
        }
    }

    {
        let (mut sdf, _header) = SeqDataReaderSeek::<H>::open(sdf_file).unwrap();
        let r2 = sdf.next_at(pos[1]).unwrap();
        assert_eq!(r2, DATA2);
        let r1 = sdf.next_at(pos[0]).unwrap();
        assert_eq!(r1, DATA1);
        let r3 = sdf.next_at(pos[2]).unwrap();
        assert_eq!(r3, DATA3);
    }
}
source

pub fn next(&mut self) -> Result<Vec<u8>>

Return the next block along with the current offset if it exists, or None if reached the end of file.

source

pub fn next_at(&mut self, pos: u64) -> Result<Vec<u8>>

Return the next block at the offset specified

Note that if the position specified is not a valid boundary, then arbitrary invalid stuff might be returns, or some Err related to reading data

Examples found in repository?
examples/run.rs (line 74)
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
fn run_writer_reader<H: SeqDataFormat>(sdf_file: &Path) {
    {
        let header = vec![0x90; H::HEADER_SIZE];
        let mut sdf = SeqDataWriter::<H>::create(&sdf_file, &header).unwrap();
        sdf.append(DATA1).unwrap();
        sdf.append(DATA2).unwrap();
        sdf.append(DATA3).unwrap();
    }

    let mut pos = Vec::new();
    {
        let (mut sdf, _header) = SeqDataReader::<H>::open(&sdf_file).unwrap();
        let (p1, r1) = sdf.next().unwrap().unwrap();
        let (p2, r2) = sdf.next().unwrap().unwrap();
        let (p3, r3) = sdf.next().unwrap().unwrap();

        pos.push(p1);
        pos.push(p2);
        pos.push(p3);

        assert_eq!(p1, 0);
        assert_eq!(r1, DATA1);

        assert_eq!(p2, 4 + DATA1.len() as u64);
        assert_eq!(r2, DATA2);

        assert_eq!(p3, 4 * 2 + DATA1.len() as u64 + DATA2.len() as u64);
        assert_eq!(r3, DATA3);

        if let Some(x) = sdf.next() {
            panic!("more data than expected {:?}", x)
        }
    }

    {
        let (mut sdf, _header) = SeqDataReaderSeek::<H>::open(sdf_file).unwrap();
        let r2 = sdf.next_at(pos[1]).unwrap();
        assert_eq!(r2, DATA2);
        let r1 = sdf.next_at(pos[0]).unwrap();
        assert_eq!(r1, DATA1);
        let r3 = sdf.next_at(pos[2]).unwrap();
        assert_eq!(r3, DATA3);
    }
}

Auto Trait Implementations§

§

impl<Format> Freeze for SeqDataReaderSeek<Format>

§

impl<Format> RefUnwindSafe for SeqDataReaderSeek<Format>
where Format: RefUnwindSafe,

§

impl<Format> Send for SeqDataReaderSeek<Format>
where Format: Send,

§

impl<Format> Sync for SeqDataReaderSeek<Format>
where Format: Sync,

§

impl<Format> Unpin for SeqDataReaderSeek<Format>
where Format: Unpin,

§

impl<Format> UnwindSafe for SeqDataReaderSeek<Format>
where Format: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.