#array #static #heap-allocation #allocation #heap-allocated #heap

no-std static-array

A no-std rust crate providing a heap-allocated non-resizable type-checked array

5 releases (breaking)

0.5.0 Jan 25, 2024
0.4.0 Jan 25, 2024
0.3.0 Jan 15, 2024
0.2.0 Jan 15, 2024
0.1.0 Jan 13, 2024

#108 in No standard library

Download history 13/week @ 2024-01-26 6/week @ 2024-02-23 1/week @ 2024-03-01 3/week @ 2024-03-08 8/week @ 2024-03-15 68/week @ 2024-03-22 2/week @ 2024-03-29

56 downloads per month
Used in surface-grid

BSD-3-Clause

33KB
677 lines

Static Array

A no-std rust crate providing a heap-allocated non-resizable type-checked array.

The documentation is available at https://docs.rs/static-array/0.5.0.

The following types are provided:

  • HeapArray - A one dimensional heap-allocated array.
  • HeapArray2D - A two dimensional heap-allocated array.
  • HeapArray3D - A three dimensional heap-allocated array.

This crate does not depend on std but does require alloc in order to create the array.

Examples

Creating a large array on the heap using a function.

use static_array::HeapArray;

// Creates an array 16 MB (on 64 bit systems) in size
// which is larger than the standard linux stack size.
let array: HeapArray<usize, 2000000> = HeapArray::from_fn(|i| i);

assert_eq!(1247562, array[1247562]);

Creating a large array from the default value of a type.

use static_array::HeapArray;

let array: HeapArray<usize, 2000000> = HeapArray::default();

assert_eq!(0, array[1247562]);

lib.rs:

A no-std rust crate providing a heap-allocated non-resizable type-checked array. The following types are provided:

  • HeapArray - A one dimensional heap-allocated array.
  • HeapArray2D - A two dimensional heap-allocated array.
  • HeapArray3D - A three dimensional heap-allocated array.

This crate does not depend on std but does require alloc in order to create the array.

Examples

Creating a large array on the heap using a function.

use static_array::HeapArray;

// Creates an array 16 MB (on 64 bit systems) in size which is larger than the standard linux stack size.
let array: HeapArray<usize, 2000000> = HeapArray::from_fn(|i| i);

assert_eq!(1247562, array[1247562]);

Creating a large array from the default value of a type.

use static_array::HeapArray;

let array: HeapArray<usize, 2000000> = HeapArray::default();

assert_eq!(0, array[1247562]);

Dependencies

~0–265KB