drm_ffi/
utils.rs

1/// Takes an `Option<&mut Vec<T>>` style buffer and gets its pointer.
2macro_rules! map_ptr {
3    ($buffer:expr) => {
4        match $buffer {
5            Some(b) => b.as_ptr() as _,
6            None => 0 as _,
7        }
8    };
9}
10
11/// Takes an `Option<&mut Vec<T>>` style buffer and gets its allocated length.
12macro_rules! map_len {
13    ($buffer:expr) => {
14        match $buffer {
15            Some(b) => b.capacity() as _,
16            None => 0,
17        }
18    };
19}
20
21/// Takes an `Option<&mut Vec<T>>` style buffer and shrinks it.
22macro_rules! map_reserve {
23    ($buffer:expr, $size:expr) => {
24        match $buffer {
25            Some(ref mut b) => b.reserve_exact($size - b.len()),
26            _ => (),
27        }
28    };
29}
30/// Takes an `Option<&mut Vec<T>>` style buffer and shrinks it.
31macro_rules! map_set {
32    ($buffer:expr, $min:expr) => {
33        match $buffer {
34            Some(ref mut b) => unsafe { b.set_len($min) },
35            _ => (),
36        }
37    };
38}