Skip to main content

MainHeaderBuilder

Struct MainHeaderBuilder 

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

Utility to easily generate a MainHeader.

Implementations§

Source§

impl MainHeaderBuilder

Source

pub fn new() -> MainHeaderBuilder

Creates a new main header builder.

Source

pub fn with_type(self, typeb: u8) -> Self

Defines the BPX type byte.

The default value of the type byte is 0.

§Arguments
  • typeb: the BPX type byte.

returns: MainHeaderBuilder

§Examples
use bpx::builder::MainHeaderBuilder;

let header = MainHeaderBuilder::new()
    .with_type('M' as u8)
    .build();
assert_eq!(header.btype, 'M' as u8);
Source

pub fn with_type_ext(self, type_ext: [u8; 16]) -> Self

Defines the Extended Type Information field of the BPX.

By default Extended Type Information is filled with zeros.

§Arguments
  • type_ext: the Extended Type Information block.

returns: MainHeaderBuilder

§Examples
use bpx::builder::MainHeaderBuilder;

let header = MainHeaderBuilder::new()
    .with_type_ext([1; 16])
    .build();
assert_eq!(header.type_ext, [1; 16]);
Source

pub fn with_version(self, version: u32) -> Self

Defines the version of the BPX.

The default value of the version int is given by BPX_CURRENT_VERSION.

Note: A version which is not specified in KNOWN_VERSIONS will cause the decoder to fail loading the file, complaining that the file is corrupted.

§Arguments
  • version: the new version of the BPX.

returns: MainHeaderBuilder

§Examples
use bpx::builder::MainHeaderBuilder;

let header = MainHeaderBuilder::new()
    .with_version(1)
    .build();
assert_eq!(header.version, 1);
Source

pub fn build(self) -> MainHeader

Consumes self and returns the generated MainHeader.

§Examples
use bpx::builder::MainHeaderBuilder;

let header = MainHeaderBuilder::new()
    .with_type('M' as u8)
    .with_type_ext([1; 16])
    .with_version(1)
    .build();
assert_eq!(header.btype, 'M' as u8);
assert_eq!(header.type_ext, [1; 16]);
assert_eq!(header.version, 1);

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.