File: const_generics_arrayvec.rs

package info (click to toggle)
rust-cbindgen 0.27.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,616 kB
  • sloc: ansic: 15; makefile: 11
file content (17 lines) | stat: -rw-r--r-- 371 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#[repr(C)]
pub struct ArrayVec<T, const CAP: usize> {
    // the `len` first elements of the array are initialized
    xs: [T; CAP],
    len: u32,
}

#[no_mangle]
pub unsafe extern "C" fn push(v: *mut ArrayVec<*mut u8, 100>, elem: *mut u8) -> i32 {
    if (*v).len < 100 {
        (*v).xs[(*v).len] = elem;
        (*v).len += 1;
        1
    } else {
        0
    }
}