pub struct Reader { /* private fields */ }
Expand description
Abstraction layer for reading UTF tables
Implementations§
Source§impl Reader
impl Reader
Sourcepub fn new(reader: &mut dyn Read) -> Result<Reader>
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)?;
Sourcepub fn field_count(&self) -> u16
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);
Sourcepub fn table_name<'a>(&'a self) -> &'a str
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");
Sourcepub fn more_column_data(&self) -> bool
pub fn more_column_data(&self) -> bool
Sourcepub fn more_row_data(&self) -> bool
pub fn more_row_data(&self) -> bool
Sourcepub fn read_constant_column<T: Value>(
&mut self,
name: &'static str,
) -> Result<T>
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")?;
Sourcepub fn read_constant_column_opt<T: Value>(
&mut self,
name: &'static str,
) -> Result<Option<T>>
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")?;
Sourcepub fn read_rowed_column<T: Value>(&mut self, name: &'static str) -> Result<()>
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")?;
Sourcepub fn read_rowed_column_opt<T: Value>(
&mut self,
name: &'static str,
) -> Result<bool>
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");
}