DecoderBuilder

Struct DecoderBuilder 

Source
pub struct DecoderBuilder<T: Topology> { /* private fields */ }
Expand description

Builder for constructing DecodingState instances.

The builder pattern eliminates the need to manually calculate STRIDE_Y, preventing the common pitfall of mismatched const generics.

§Type Parameter

§Example

use prav_core::{Arena, DecoderBuilder, SquareGrid, required_buffer_size};

let size = required_buffer_size(64, 64, 1);
let mut buffer = vec![0u8; size];
let mut arena = Arena::new(&mut buffer);

let decoder = DecoderBuilder::<SquareGrid>::new()
    .dimensions(64, 64)
    .build(&mut arena)
    .expect("Failed to build decoder");

Implementations§

Source§

impl<T: Topology> DecoderBuilder<T>

Source

pub const fn new() -> Self

Creates a new decoder builder with default dimensions.

You must call dimensions or dimensions_3d before build.

Source

pub const fn dimensions(self, width: usize, height: usize) -> Self

Sets the grid dimensions for a 2D code.

§Arguments
  • width - Grid width in nodes.
  • height - Grid height in nodes.
Source

pub const fn dimensions_3d( self, width: usize, height: usize, depth: usize, ) -> Self

Sets the grid dimensions for a 3D code.

§Arguments
  • width - Grid width in nodes.
  • height - Grid height in nodes.
  • depth - Grid depth in nodes.
Source

pub const fn stride_y(&self) -> usize

Calculates the required STRIDE_Y for the configured dimensions.

This is the value that would need to be specified as the const generic when using DecodingState directly.

Source

pub fn build<'a>( self, arena: &mut Arena<'a>, ) -> Result<DynDecoder<'a, T>, &'static str>

Builds the decoder with the appropriate STRIDE_Y.

This method uses a dispatch table to select the correct const generic at runtime, then constructs the decoder.

§Errors

Returns an error if:

  • Dimensions are not set (width or height is 0).
  • The grid is too large (max dimension > 512).
§Example
let decoder = DecoderBuilder::<SquareGrid>::new()
    .dimensions(32, 32)
    .build(&mut arena)?;

Trait Implementations§

Source§

impl<T: Topology> Default for DecoderBuilder<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for DecoderBuilder<T>

§

impl<T> RefUnwindSafe for DecoderBuilder<T>
where T: RefUnwindSafe,

§

impl<T> Send for DecoderBuilder<T>
where T: Send,

§

impl<T> Sync for DecoderBuilder<T>
where T: Sync,

§

impl<T> Unpin for DecoderBuilder<T>
where T: Unpin,

§

impl<T> UnwindSafe for DecoderBuilder<T>
where T: UnwindSafe,

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.