Description
I was wondering whether there was a best practive when writing functions that expect arrays, specifically when they are not taking ownership of the array. I couldn't see this being addressed in the documentation or in an existing issue so here's a few things I think could be worth thinking about:
-
Should functions prefer to take
ArrayView
over the equivalentArray
, and what about using a pointer vs by value? For example, which of the following would be 'best'?fn sum(a: ArrayView1<f64>) -> f64; fn sum(a: &ArrayView1<f64>) -> f64; fn sum(a: &Array1<f64>) -> f64;
-
When muteable data is expected, is there a preference to using
ArrayViewMut
vs&mut Array
?fn increment(mut a: ArrayViewMut1<f64>) -> f64; fn increment(a: &mut Array1<f64>) -> f64;
I would expect that for most applications, the ArrayView
and ArrayViewMut
are preferred as they are more general.
Is the fact that they are views into an array mean that they behave more like pointers and thus &ArrayView
is redundant?