macro_rules! none_cell_arr {
($t:ty; $n:expr) => { ... };
}Expand description
Creates an array of type [Cell<Option<T>>; N] and default-initializes it to Cell:new(None)
for every element. Similar to none_arr, plus a Cell.
§Macro Arguments
$t- The type to wrap into anCell<Option<T>>.$n- The number of elements for the array.
§Example
When dealing with non-Copy/Clone types, arrays of type [Option<T>; N] cannot be
created even though the default type None could be applied:
ⓘ
// This type does not implement Copy/Clone.
struct Complicated;
// Fails with "the trait `Copy` is not implemented for `Complicated`":
let arr: [Cell<Option<Complicated>>; 10] = [Cell::new(None); 10];This crate simplifies array creation of these cases through the none_cell_arr macro:
let arr = none_cell_arr![Complicated; 10];
// The result is an array of Cell<Option<Complicated>>.
let arr: [Cell<Option<Complicated>>; 10] = arr;
assert_eq!(arr.len(), 10);
for item in arr.into_iter() {
assert!(item.take().is_none());
}