MCPcopy Index your code
hub / github.com/Manishearth/array-init

github.com/Manishearth/array-init @v2.0.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.0.1 ↗ · + Follow
20 symbols 42 edges 1 files 5 documented · 25%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

array-init

Crates.io Docs

The array-init crate allows you to initialize arrays with an initializer closure that will be called once for each element until the array is filled.

This way you do not need to default-fill an array before running initializers. Rust currently only lets you either specify all initializers at once, individually ([a(), b(), c(), ...]), or specify one initializer for a Copy type ([a(); N]), which will be called once with the result copied over.

Care is taken not to leak memory shall the initialization fail.

Examples:

// Initialize an array of length 50 containing
// successive squares

let arr: [usize; 50] = array_init::array_init(|i| i * i);

// Initialize an array from an iterator
// producing an array of [1,2,3,4] repeated

let four = [1,2,3,4];
let mut iter = four.iter().copied().cycle();
let arr: [u32; 50] = array_init::from_iter(iter).unwrap();

// Closures can also mutate state. We guarantee that they will be called
// in order from lower to higher indices.

let mut last = 1u64;
let mut secondlast = 0;
let fibonacci: [u64; 50] = array_init::array_init(|_| {
    let this = last + secondlast;
    secondlast = last;
    last = this;
    this
});

Licensing

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Core symbols most depended-on inside this repo

array_init
called by 3
src/lib.rs
new_element
called by 3
src/lib.rs
from_iter
called by 2
src/lib.rs
try_array_init
called by 2
src/lib.rs
from_iter_reversed
called by 1
src/lib.rs
assert_no_leaks
called by 1
src/lib.rs
try_array_init_impl
called by 0
src/lib.rs
drop
called by 0
src/lib.rs

Shape

Function 11
Method 5
Class 3
Enum 1

Languages

Rust100%

Modules by API surface

src/lib.rs20 symbols

For agents

$ claude mcp add array-init \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact