Reader

Struct Reader 

Source
pub struct Reader { /* private fields */ }
Expand description

Abstraction layer for reading UTF tables

Implementations§

Source§

impl Reader

Source

pub fn new(reader: &mut dyn Read) -> Result<Reader>

Creates a new Reader

Preliminary validity checks are performed as well.

§Example
let mut file = File::open("random-table.bin")?;
let reader = Reader::new(&mut file)?;
Source

pub fn field_count(&self) -> u16

Returns the number of columns in the table being read

§Example
let mut file = File::open("random-table.bin")?;
let reader = Reader::new(&mut file)?;
assert_eq!(reader.field_count(), 7u16);
Source

pub fn table_name<'a>(&'a self) -> &'a str

Returns the name of the table being read

§Example
let mut file = File::open("random-table.bin")?;
let reader = Reader::new(&mut file)?;
assert_eq!(reader.table_name(), "ImportantTable");
Source

pub fn more_column_data(&self) -> bool

Returns true if there is more data in the column data section, or false otherwise.

§Example
let mut file = std::fs::File::open("random-table.bin")?;
let reader = criware_utf_core::Reader::new(&mut file)?;
// ... column reading code ...
if reader.more_column_data() {
    panic!();
}
Source

pub fn more_row_data(&self) -> bool

Returns true if there is more data in the row data section, or false otherwise.

§Example
let mut file = std::fs::File::open("random-table.bin")?;
let reader = criware_utf_core::Reader::new(&mut file)?;
// ... column reading code ...
while reader.more_row_data() {
    // ... row reading code ...
}
Source

pub fn read_constant_column<T: Value>( &mut self, name: &'static str, ) -> Result<T>

Attempts to read a constant column with the given name and type.

If the column matches, the column’s value is returned. If the next column stored does not match, an error is returned.

§Example
let file_count: u64 = reader.read_constant_column("FileCount")?;
let version: String = reader.read_constant_column("Version")?;
Source

pub fn read_constant_column_opt<T: Value>( &mut self, name: &'static str, ) -> Result<Option<T>>

Attempts to read an optional constant column with the given name and type.

If the name and type of value of the next column stored does not match, this function will return an error. The storage method of the column may be constant or zero. If it’s constant, the column’s value is returned.

§Example
let file_count: u64 = reader.read_constant_column("FileCount")?;
let version: String = reader.read_constant_column("Version")?;
let crc32: Option<u32> = reader.read_constant_column_opt::<u32>("Crc")?;
Source

pub fn read_rowed_column<T: Value>(&mut self, name: &'static str) -> Result<()>

Attempts to read a rowed column with the given name and type.

If the next column stored does not match, an error is returned.

§Example
reader.read_constant_column::<i32>("ID")?;
reader.read_constant_column::<String>("Name")?;
Source

pub fn read_rowed_column_opt<T: Value>( &mut self, name: &'static str, ) -> Result<bool>

Attempts to read an optional rowed column with the given name and type.

If the name and type of value of the next column stored does not match, this function will return an error. The storage method of the column may be rowed or zero. true denotes that the column is rowed, false denotes the column is zero.

§Example
let crc_included: bool = reader.read_rowed_column_opt::<u32>("Crc")?;
if crc_included {
    println!("CRC32 checksums are included with each file!");
} else {
    println!("No checksums found");
}
Source

pub fn read_value<T: Value>(&mut self, row: bool) -> Result<T>

Attempts to read a value from the column or row buffer.

§Example
while reader.more_row_data() {
    let name: String = reader.read_value(true)?;
    let crc32: u32 = reader.read_value(true)?;
    // ...
}

Auto Trait Implementations§

§

impl Freeze for Reader

§

impl RefUnwindSafe for Reader

§

impl Send for Reader

§

impl Sync for Reader

§

impl Unpin for Reader

§

impl UnwindSafe for Reader

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.