MCPcopy Create free account
hub / github.com/cpmech/plotpy / AsVector

Interface AsVector

src/as_vector.rs:33–39  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

31/// assert_eq!(sum(&z), 600.0);
32/// ```
33pub 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)
42impl<'a, U: 'a> AsVector<'a, U> for Vec<U>

Callers

nothing calls this directly

Implementers 1

as_vector.rssrc/as_vector.rs

Calls

no outgoing calls

Tested by

no test coverage detected