pub struct ConfReaderOptions { /* private fields */ }
Expand description
Builder struct to allow for configuring the eventual call to read from a file It has two primary properties:
- Magic bytes: the bytes used to
- Window size: the size of the window used to scan the file. This library will read in twice the window size to fill its internal buffer
§Example
use catconf::ConfReaderOptions;
let conf = ConfReaderOptions::new(b"CATCONF".to_vec()).read_from_exe()?;
Implementations§
Source§impl ConfReaderOptions
impl ConfReaderOptions
Sourcepub fn new(bytes: Vec<u8>) -> Self
pub fn new(bytes: Vec<u8>) -> Self
Create a new ConfReaderOptions builder with the magic bytes specified.
The window size is initially set to 2048
§Example
use catconf::ConfReaderOptions;
let mut options = ConfReaderOptions::new(b"CATCONF".to_vec());
let conf = options.window_size(4096).read_from_exe()?;
Sourcepub fn magic_bytes(&mut self, bytes: Vec<u8>) -> &mut Self
pub fn magic_bytes(&mut self, bytes: Vec<u8>) -> &mut Self
Set the magic bytes to a different value
§Example
use catconf::ConfReaderOptions;
let options = ConfReaderOptions::new(b"CATCONF".to_vec())
.magic_bytes(b"NOTCATCONF".to_vec())
.read_from_exe()?;
Sourcepub fn window_size(&mut self, size: u32) -> &mut Self
pub fn window_size(&mut self, size: u32) -> &mut Self
Sets the window size, influencing the amount of reads that are performed on disk
§Example
use catconf::ConfReaderOptions;
let conf = ConfReaderOptions::new(b"CATCONF".to_vec())
.window_size(4096)
.read_from_exe()?;
Sourcepub fn read<F>(&self, input: &mut F) -> Result<Vec<u8>>
pub fn read<F>(&self, input: &mut F) -> Result<Vec<u8>>
Takes the configuration options provided and actually reads from the input file to gather the configuration
§Example
use catconf::ConfReaderOptions;
let conf = ConfReaderOptions::new(b"CATCONF".to_vec())
.read(&mut input);
Sourcepub fn read_from_exe(&self) -> Result<Vec<u8>>
pub fn read_from_exe(&self) -> Result<Vec<u8>>
Helper method to go along with ConfReaderOptions::read
in order to read from the
program currently checking for configuration
Functionally equivalent to:
use catconf::ConfReaderOptions;
let mut current_exe = std::fs::OpenOptions::new().read(true).open(std::env::current_exe()?)?;
let conf = ConfReaderOptions::new(b"CATCONF".to_vec()).read(&mut current_exe)?;
§Example
use catconf::ConfReaderOptions;
let conf = ConfReaderOptions::new(b"CATCONF".to_vec()).read_from_exe()?;
Auto Trait Implementations§
impl Freeze for ConfReaderOptions
impl RefUnwindSafe for ConfReaderOptions
impl Send for ConfReaderOptions
impl Sync for ConfReaderOptions
impl Unpin for ConfReaderOptions
impl UnwindSafe for ConfReaderOptions
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more