Table

Trait Table 

Source
pub trait Table: Sized {
    // Required methods
    fn new() -> Self;
    fn read(reader: &mut dyn Read) -> Result<Self, Error>;
    fn write(&self, writer: &mut dyn Write) -> Result<(), Error>;
}
Expand description

A UTF table that can be read, written, and constructed from nothing

Required Methods§

Source

fn new() -> Self

Creates a new table with default constant values and no rows

§Example
#[utf_table]
struct Tab {
    #[constant]
    constant: i32,
    row_value: i64,
}

fn main() {
    let table = Tab::new();
    assert_eq!(table.constants.constant, 0);
    assert_eq!(table.rows.len(), 0);
}
Source

fn read(reader: &mut dyn Read) -> Result<Self, Error>

Reads a table from the given stream

If the table is malformed, or if the table’s schema does not match this type, then this function will fail.

§Example
#[utf_table]
struct Tab {
    #[constant]
    constant: i32,
    row_value: i64,
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut file = File::open("table.bin")?;
    let table = Tab::read(&mut file)?;
    // ... do something ...
    Ok(())
}
Source

fn write(&self, writer: &mut dyn Write) -> Result<(), Error>

Writes a table to the given stream

§Example
#[utf_table]
struct Tab {
    #[constant]
    constant: i32,
    row_value: i64,
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut file = File::create("table.bin")?;
    let table = Tab::new();
    // ... do something ...
    table.write(&mut file)?;
    Ok(())
}

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§