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
T- The topology type (e.g.,SquareGrid).
§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>
impl<T: Topology> DecoderBuilder<T>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new decoder builder with default dimensions.
You must call dimensions or
dimensions_3d before build.
Sourcepub const fn dimensions(self, width: usize, height: usize) -> Self
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.
Sourcepub const fn dimensions_3d(
self,
width: usize,
height: usize,
depth: usize,
) -> Self
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.
Sourcepub const fn stride_y(&self) -> usize
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.
Sourcepub fn build<'a>(
self,
arena: &mut Arena<'a>,
) -> Result<DynDecoder<'a, T>, &'static str>
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§
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> 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