Trait Version

Source
pub trait Version: Sized {
    type Item;

    const VERSION: u8;
    const MAGIC_NUMBER: [u8; 8];

    // Required methods
    fn create_record_buf(index: &Index<Self>) -> Record<usize, Self::Item>;
    fn read_index_record<R>(reader: &mut R) -> Result<Record<Self>, Error>
       where R: BufRead;
    fn read_item<R>(
        reader: &mut R,
        buf: &mut Self::Item,
    ) -> Result<ReadStatus, Error>
       where R: BufRead;
    fn write_index_record<W>(
        writer: &mut W,
        record: &Record<Self>,
    ) -> Result<(), Error>
       where W: Write;
    fn write_item<W>(writer: &mut W, item: &Self::Item) -> Result<(), Error>
       where W: Write;
    fn write_record<W, I>(
        writer: &mut Writer<W, Self>,
        record: &Record<I, Self::Item>,
    ) -> Result<(), Error>
       where W: Write,
             I: AsRef<str>;

    // Provided methods
    fn read_record<R>(
        reader: &mut Reader<R, Self>,
        buf: &mut Record<usize, Self::Item>,
    ) -> Result<ReadStatus, Error>
       where R: BufRead { ... }
    fn read_magic<R>(reader: &mut R) -> Result<(), Error>
       where R: BufRead { ... }
    fn write_magic<W>(writer: &mut W) -> Result<(), Error>
       where W: Write { ... }
}
Expand description

A type that describes a SAF file version.

Users should not generally need to use methods defined by this trait directly. Rather, these methods are used by struct generic over methods instead.

Required Associated Constants§

Source

const VERSION: u8

The numeric description of the SAF version.

Source

const MAGIC_NUMBER: [u8; 8]

The SAF version magic number.

Required Associated Types§

Source

type Item

The items contained in the SAF item file for this version.

Required Methods§

Source

fn create_record_buf(index: &Index<Self>) -> Record<usize, Self::Item>

Creates a SAF record buffer suitable for reading from a reader for this version.

Source

fn read_index_record<R>(reader: &mut R) -> Result<Record<Self>, Error>
where R: BufRead,

Reads the SAF index record for this version from a reader.

Source

fn read_item<R>( reader: &mut R, buf: &mut Self::Item, ) -> Result<ReadStatus, Error>
where R: BufRead,

Reads a single item from a reader into a provided buffer.

The stream is assumed to be positioned immediately before the start of the item.

Source

fn write_index_record<W>( writer: &mut W, record: &Record<Self>, ) -> Result<(), Error>
where W: Write,

Writes the SAF index record for to a reader.

Source

fn write_item<W>(writer: &mut W, item: &Self::Item) -> Result<(), Error>
where W: Write,

Writes a single item to a writer.

Source

fn write_record<W, I>( writer: &mut Writer<W, Self>, record: &Record<I, Self::Item>, ) -> Result<(), Error>
where W: Write, I: AsRef<str>,

Writes a single record to a writer.

Provided Methods§

Source

fn read_record<R>( reader: &mut Reader<R, Self>, buf: &mut Record<usize, Self::Item>, ) -> Result<ReadStatus, Error>
where R: BufRead,

Reads a single record from a SAF reader into a provided buffer.

The stream is assumed to be positioned immediately before the start of the record.

Note that the record buffer needs to be correctly set up. Use Self::create_record_buf for a correctly initialised record buffer to use for reading.

Source

fn read_magic<R>(reader: &mut R) -> Result<(), Error>
where R: BufRead,

Reads the SAF version magic number from a reader.

Source

fn write_magic<W>(writer: &mut W) -> Result<(), Error>
where W: Write,

Writes the SAF version magic number to a writer.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§