Struct block_grid::BlockGrid[][src]

pub struct BlockGrid<T, B: BlockDim> { /* fields omitted */ }
Expand description

A fixed-size 2D array with a blocked memory representation.

See crate-level documentation for general usage info.

If your dimensions are not a multiple of the block size, you can use the helper function BlockDim::round_up_to_valid to generate larger, valid dimensions.

Implementations

Constructs a BlockGrid<T, B> by consuming a Vec<T>.

The ordering of the memory is taken as is in the vector.

Errors

If invalid dimensions, either because rows and cols do not divide evenly into the block size B or the length of elems does not match rows * cols.

Converts a BlockGrid<T, B> to a Vec<T> in memory order.

Returns the nuumber of rows.

Returns the number of columns.

Returns the number of elements.

Returns the number of blocks in the vertical direction.

Returns the number of blocks in the horizontal direction.

Returns the total number of blocks.

Returns true if the given coordinates are valid.

Returns a reference to the element at the given coordinates, or None if they are out-of-bounds.

Returns a mutable reference to the element at the given coordinates, or None if they are out-of-bounds.

Returns a reference to the element at the given coordinates, without bounds checking.

Safety

Calling this method with out-of-bounds coordinates is undefined-behaviour.

Returns a mutable reference to the element at the given coordinates, without bounds checking.

Safety

Calling this method with out-of-bounds coordinates is undefined-behaviour.

Returns all elements as a slice in memory order.

Returns all elements as a mutable slice in memory order.

Returns an iterator over all the elements in memory order.

If you wanna visit each element arbitrarily, this would be the best way. If you also need coordinates while iterating, follow up with a chained .coords() call.

Returns a mutable iterator over all the elements in memory order.

If you wanna mutably visit each element arbitrarily, this would be the best way. If you also need coordinates while iterating, follow up with a chained .coords() call.

Returns an iterator over all blocks in memory order, yielding Blocks.

If you need the block coordinates while iterating, follow up with a chained .coords() call. In this case, note that the 2D coordinates yielded are of the actual entire block. If you instead need the coordinates of the first (top-left) element in the block, see Block::starts_at.

Returns a mutable iterator over all blocks in memory order, yielding BlockMuts.

If you need the block coordinates while iterating, follow up with a chained .coords() call. In this case, note that the 2D coordinates yielded are of the actual entire block. If you instead need the coordinates of the first (top-left) element in the block, see BlockMut::starts_at.

Returns an iterator over all the elements in row-major order.

This ordering is what you’re probably used to with usual 2D arrays. This method may be useful for converting between array types or general IO. If you also need the coordinates while iterating, follow up with a chained .coords() call.

Returns an mutable iterator over all the elements in row-major order.

If you also need the coordinates while iterating, follow up with a chained .coords() call.

Constructs a BlockGrid<T, B> by filling with a single element.

Errors

If rows and cols do not divide evenly into the block size B.

Constructs a BlockGrid<T, B> from a slice in row-major order.

This method may be useful for converting from a typical 2D array.

Errors

If invalid dimensions, either because rows and cols do not divide evenly into the block size B or the length of elems does not match rows * cols.

Constructs a BlockGrid<T, B> from a slice in column-major order.

2D arrays are not usually stored like this, but occasionally they are.

Errors

If invalid dimensions, either because rows and cols do not divide evenly into the block size B or the length of elems does not match rows * cols.

Constructs a BlockGrid<T, B> by filling with the default value of T.

Errors

If rows and cols do not divide evenly into the block size B.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

Performs the mutable indexing (container[index]) operation. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.