summaryrefslogtreecommitdiffstats
path: root/tests/rust/const_generics_arrayvec.rs
blob: 459ddbcbb6de14e2a902d31d4eec238d751cc241 (plain)
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
    }
}