You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
array![..(0..=3)] => compile error - size must be given when using spread operator
array_from![0,1,2,3] => [0.into(), 1.into(), 2.into(), 3.into()] (and the same treatment for all examples below)
array![1; 4] => [1, 1, 1, 1] (not [1; 4] because we don't want to require Copy)
array![1; non_constant_var] => compile error - length must be constant
array![0, 1; 4] => Need to decide on one of:
panic - not enough elements
compile error - not enough elements (I'm currently favouring this option)
[0,1,0,1] (repeat the sequence)
[0,1,1,1] (repeat final element)
array![..(0..100); 4] => [0,1,2,3] (no error on too many elements when the last arg is a spread)
array![0, 1, 2, 3, ..(0..100); 4] => panic - too many elements (the array was already "full" before the final spread)
array![0, 1, ..(2..5), ..(0..100); 4] => panic - too many elements (the array was already "full" before the final spread)
array![0, 1, ..(2..); 4] => [0,1,2,3]
array![..(0..2); 4] => panic - not enough elements
array![0, ..(1..2); 4] => panic - not enough elements
Implementation:
This will require a little refactoring of VecInput so that its internals can be re-used.
It should be ok for the macro to accept any expression for the length. If the expression is not constant, the generated code should produce a suitable error without extra effort.
special cases for:
array![0,1,2,3] (no length specified)
array![1; 4] (repeat given element)
the other variants can write to a [MaybeUninit<T>; n] from a sequence of iterators.
If the length is larger than the number of provided elements, it often will not be possible to detect until runtime. It should:
panic, with a suitable error message
before panic, clean up the partially initialized array to avoid memory leaks.
The text was updated successfully, but these errors were encountered:
Array initialiizer macros.
Usage / test cases:
array![0,1,2,3]
=>[0,1,2,3]
array![..(0..=3)]
=> compile error - size must be given when using spread operatorarray_from![0,1,2,3]
=>[0.into(), 1.into(), 2.into(), 3.into()]
(and the same treatment for all examples below)array![1; 4]
=>[1, 1, 1, 1]
(not[1; 4]
because we don't want to requireCopy
)array![1; non_constant_var]
=> compile error - length must be constantarray![0, 1; 4]
=> Need to decide on one of:[0,1,0,1]
(repeat the sequence)[0,1,1,1]
(repeat final element)array![..(0..100); 4]
=>[0,1,2,3]
(no error on too many elements when the last arg is a spread)array![0, 1, 2, 3, ..(0..100); 4]
=> panic - too many elements (the array was already "full" before the final spread)array![0, 1, ..(2..5), ..(0..100); 4]
=> panic - too many elements (the array was already "full" before the final spread)array![0, 1, ..(2..); 4]
=>[0,1,2,3]
array![..(0..2); 4]
=> panic - not enough elementsarray![0, ..(1..2); 4]
=> panic - not enough elementsImplementation:
VecInput
so that its internals can be re-used.array![0,1,2,3]
(no length specified)array![1; 4]
(repeat given element)[MaybeUninit<T>; n]
from a sequence of iterators.The text was updated successfully, but these errors were encountered: