1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! [`HostSlice`] — generic abstraction over "things that are a slice of `T`".
/// Trait for host-memory values that can be viewed as `&[T]`.
///
/// Safe-API wrappers in baracuda (and downstream crates) use this to accept
/// any of the common host-memory containers (`&[T]`, `Vec<T>`, `Box<[T]>`,
/// fixed-size arrays, and so on) without forcing the caller to write
/// `.as_slice()` explicitly.
///
/// The blanket impl over `AsRef<[T]>` covers every standard collection out
/// of the box. User types can implement it directly if they need custom
/// behavior (e.g. a memory-mapped file that decodes on read).
///
/// # Example
///
/// ```
/// use baracuda_types::HostSlice;
///
/// fn sum<T: core::ops::AddAssign + Default + Copy, S: HostSlice<T>>(slice: S) -> T {
/// let mut acc = T::default();
/// for &v in slice.as_host_slice() {
/// acc += v;
/// }
/// acc
/// }
///
/// assert_eq!(sum(vec![1u32, 2, 3]), 6);
/// assert_eq!(sum([1.0f32, 2.0, 3.0]), 6.0);
/// assert_eq!(sum(&[1i8, 2, 3][..]), 6);
/// ```