custos/static_api/
macros.rs1#[cfg_attr(feature = "cpu", doc = "```")]
5#[cfg_attr(not(feature = "cpu"), doc = "```ignore")]
6#[macro_export]
15macro_rules! buf {
16 ($elem:expr; $n:expr) => (
17 if $n == 0 {
18 panic!("The length of the buffer can't be 0.");
19 } else {
20 $crate::Buffer::from(vec![$elem; $n])
21 }
22 );
23
24 ($($x:expr),+ $(,)?) => (
25 $crate::Buffer::<_, $crate::CPU, ()>::from([$($x),+])
26 );
27
28 ($device:expr, [($x:expr),+ $(,)?]) => (
30 $crate::Buffer::<_, _, 0>::from((&device, [$($x),+]))
31 )
32}
33
34#[cfg(test)]
35mod tests {
36 #[test]
37 fn test_macro_filling() {
38 let buf = buf![2.; 10];
39 assert_eq!(buf.as_slice(), &[2.; 10]);
40 }
41
42 #[test]
43 fn test_macro_from_slice() {
44 let buf = buf![5, 3, 2, 6, 2];
45 assert_eq!(buf.as_slice(), &[5, 3, 2, 6, 2])
46 }
47}