New type GenericParam represents a generic parameter.
This commit is contained in:
committed by
Emilio Cobos Álvarez
parent
13c0a4a2e8
commit
c732069b2e
@@ -0,0 +1,15 @@
|
||||
#[repr(transparent)]
|
||||
pub struct CArrayString<const CAP: usize> {
|
||||
pub chars: [i8; CAP],
|
||||
}
|
||||
|
||||
pub const TITLE_SIZE: usize = 80;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct Book {
|
||||
pub title: CArrayString<TITLE_SIZE>,
|
||||
pub author: CArrayString<40>,
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn root(a: *mut Book) {}
|
||||
@@ -0,0 +1,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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user