Struct SeqDataWriter

Source
pub struct SeqDataWriter<Format: SeqDataFormat> { /* private fields */ }
Expand description

Writer for a new SeqData

Implementations§

Source§

impl<Format: SeqDataFormat> SeqDataWriter<Format>

Source

pub fn create<P: AsRef<Path>>(path: P, header: &[u8]) -> Result<Self>

Create a new SeqData File at the location specified

If the file already exists, this call will fail

The header need to fits the size of Format::HEADER_SIZE

Examples found in repository?
examples/run.rs (line 41)
38fn run_writer_reader<H: SeqDataFormat>(sdf_file: &Path) {
39    {
40        let header = vec![0x90; H::HEADER_SIZE];
41        let mut sdf = SeqDataWriter::<H>::create(&sdf_file, &header).unwrap();
42        sdf.append(DATA1).unwrap();
43        sdf.append(DATA2).unwrap();
44        sdf.append(DATA3).unwrap();
45    }
46
47    let mut pos = Vec::new();
48    {
49        let (mut sdf, _header) = SeqDataReader::<H>::open(&sdf_file).unwrap();
50        let (p1, r1) = sdf.next().unwrap().unwrap();
51        let (p2, r2) = sdf.next().unwrap().unwrap();
52        let (p3, r3) = sdf.next().unwrap().unwrap();
53
54        pos.push(p1);
55        pos.push(p2);
56        pos.push(p3);
57
58        assert_eq!(p1, 0);
59        assert_eq!(r1, DATA1);
60
61        assert_eq!(p2, 4 + DATA1.len() as u64);
62        assert_eq!(r2, DATA2);
63
64        assert_eq!(p3, 4 * 2 + DATA1.len() as u64 + DATA2.len() as u64);
65        assert_eq!(r3, DATA3);
66
67        if let Some(x) = sdf.next() {
68            panic!("more data than expected {:?}", x)
69        }
70    }
71
72    {
73        let (mut sdf, _header) = SeqDataReaderSeek::<H>::open(sdf_file).unwrap();
74        let r2 = sdf.next_at(pos[1]).unwrap();
75        assert_eq!(r2, DATA2);
76        let r1 = sdf.next_at(pos[0]).unwrap();
77        assert_eq!(r1, DATA1);
78        let r3 = sdf.next_at(pos[2]).unwrap();
79        assert_eq!(r3, DATA3);
80    }
81}
Source

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

Open a SeqData File at the location specified

If the file already exists, this call will fail

The header need to fits the size of Format::HEADER_SIZE

Source

pub fn position(&self) -> u64

Source

pub fn append(&mut self, data: &[u8]) -> Result<()>

Append a new data chunk to this file

Examples found in repository?
examples/run.rs (line 42)
38fn run_writer_reader<H: SeqDataFormat>(sdf_file: &Path) {
39    {
40        let header = vec![0x90; H::HEADER_SIZE];
41        let mut sdf = SeqDataWriter::<H>::create(&sdf_file, &header).unwrap();
42        sdf.append(DATA1).unwrap();
43        sdf.append(DATA2).unwrap();
44        sdf.append(DATA3).unwrap();
45    }
46
47    let mut pos = Vec::new();
48    {
49        let (mut sdf, _header) = SeqDataReader::<H>::open(&sdf_file).unwrap();
50        let (p1, r1) = sdf.next().unwrap().unwrap();
51        let (p2, r2) = sdf.next().unwrap().unwrap();
52        let (p3, r3) = sdf.next().unwrap().unwrap();
53
54        pos.push(p1);
55        pos.push(p2);
56        pos.push(p3);
57
58        assert_eq!(p1, 0);
59        assert_eq!(r1, DATA1);
60
61        assert_eq!(p2, 4 + DATA1.len() as u64);
62        assert_eq!(r2, DATA2);
63
64        assert_eq!(p3, 4 * 2 + DATA1.len() as u64 + DATA2.len() as u64);
65        assert_eq!(r3, DATA3);
66
67        if let Some(x) = sdf.next() {
68            panic!("more data than expected {:?}", x)
69        }
70    }
71
72    {
73        let (mut sdf, _header) = SeqDataReaderSeek::<H>::open(sdf_file).unwrap();
74        let r2 = sdf.next_at(pos[1]).unwrap();
75        assert_eq!(r2, DATA2);
76        let r1 = sdf.next_at(pos[0]).unwrap();
77        assert_eq!(r1, DATA1);
78        let r3 = sdf.next_at(pos[2]).unwrap();
79        assert_eq!(r3, DATA3);
80    }
81}

Auto Trait Implementations§

§

impl<Format> Freeze for SeqDataWriter<Format>

§

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

§

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

§

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

§

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

§

impl<Format> UnwindSafe for SeqDataWriter<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>,

Source§

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>,

Source§

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.