1use std::rc::Rc;
4use std::slice;
5
6use crate::value::{self, Slot, StructObject, TypeDesc};
7
8#[unsafe(no_mangle)]
13pub(crate) unsafe extern "C" fn nf_struct_new(ty: &'static TypeDesc, fields: *const Slot) -> Slot {
14 let len = ty.children().len();
15 let fields = if len == 0 {
16 Box::default()
17 } else {
18 unsafe { slice::from_raw_parts(fields, len) }.into()
20 };
21 value::into_slot(Rc::new(StructObject { ty, fields }))
22}
23
24#[unsafe(no_mangle)]
26pub(crate) extern "C" fn nf_struct_get(object: Slot, index: usize) -> Slot {
27 value::as_struct(object).fields[index]
28}
29
30#[unsafe(no_mangle)]
36pub(crate) unsafe extern "C" fn nf_struct_field_mut(place: *mut Slot, index: usize) -> *mut Slot {
37 &raw mut value::struct_mut(unsafe { &mut *place }).fields[index]
39}