Defines a trait to handle Vector-like data # Example ``` use plotpy::AsVector; fn sum<'a, T, U>(array: &'a T) -> f64 where T: AsVector<'a, U>, U: 'a + Into , { let mut res = 0.0; let m = array.vec_size(); for i in 0..m { res += array.vec_at(i).into(); } res } // heap-allocated 1D array (vector) let x = vec![1.0, 2.0, 3.0]; assert_eq!(sum(&x), 6.0); // heap-allocated 1D array (slice) let y
| 31 | /// assert_eq!(sum(&z), 600.0); |
| 32 | /// ``` |
| 33 | pub trait AsVector<'a, U: 'a> { |
| 34 | /// Returns the size of the vector |
| 35 | fn vec_size(&self) -> usize; |
| 36 | |
| 37 | /// Returns the value at index i |
| 38 | fn vec_at(&self, i: usize) -> U; |
| 39 | } |
| 40 | |
| 41 | /// Defines a heap-allocated 1D array (vector) |
| 42 | impl<'a, U: 'a> AsVector<'a, U> for Vec<U> |
nothing calls this directly
no outgoing calls
no test coverage detected