catconf

Struct ConfReaderOptions

Source
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:

  1. Magic bytes: the bytes used to
  2. 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

Source

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()?;
Source

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()?;
Source

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()?;
Source

pub fn read<F>(&self, input: &mut F) -> Result<Vec<u8>>
where F: Seek + Read,

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);
Source

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§

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.