pub trait BinaryRead: Read {
// Provided methods
fn read_binary_boxed<T>(&mut self) -> Result<Box<T>> { ... }
fn read_binary<T>(&mut self) -> Result<T> { ... }
}Expand description
The BinaryRead trait allows for reading data structures out of binary sources.
§Examples
struct MyStruct {
some: char,
// fields
}
use binext::BinaryRead;
use std::{io, fs};
fn main() -> io::Result<()> {
let mut file = fs::File::open("myfile.bin")?;
// This returns an instance of the file that was in the file.
// Please note that for this method to work properly, the data must be written beforehand
// into the file.
let instance = file.read_binary::<MyStruct>()?;
Ok(())
}Provided Methods§
Sourcefn read_binary_boxed<T>(&mut self) -> Result<Box<T>>
fn read_binary_boxed<T>(&mut self) -> Result<Box<T>>
Reads from a binary source and converts the bytes into the specified structure, returning
a Boxed structure.
§Examples
struct MyStruct {
some: char,
// fields
}
use binext::BinaryRead;
use std::{io, fs};
fn main() -> io::Result<()> {
let mut file = fs::File::open("myfile.bin")?;
// This returns an instance of the file that was in the file.
// Please note that for this method to work properly, the data must be written beforehand
// into the file.
let instance = file.read_binary_boxed::<MyStruct>()?;
Ok(())
}Sourcefn read_binary<T>(&mut self) -> Result<T>
fn read_binary<T>(&mut self) -> Result<T>
Reads from a binary source and converts the bytes into the specified structure.
§Examples
struct MyStruct {
some: char,
// fields
}
use binext::BinaryRead;
use std::{io, fs};
fn main() -> io::Result<()> {
let mut file = fs::File::open("myfile.bin")?;
// This returns an instance of the file that was in the file.
// Please note that for this method to work properly, the data must be written beforehand
// into the file.
let instance = file.read_binary::<MyStruct>()?;
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.