Skip to main content

nifty_rt/abi/
values.rs

1//! Owning, comparing and storing values of any type.
2
3use crate::value::{self, Slot, TypeDesc};
4
5/// Adds an owner to `slot`, which is borrowed.
6#[unsafe(no_mangle)]
7pub(crate) extern "C" fn nf_retain(slot: Slot, ty: &TypeDesc) {
8    value::retain(slot, ty);
9}
10
11#[unsafe(no_mangle)]
12pub(crate) extern "C" fn nf_release(slot: Slot, ty: &TypeDesc) {
13    value::release(slot, ty);
14}
15
16/// `a == b`, with both borrowed.
17#[unsafe(no_mangle)]
18pub(crate) extern "C" fn nf_equal(a: Slot, b: Slot, ty: &TypeDesc) -> bool {
19    value::equal(a, b, ty)
20}
21
22/// Replaces the value in `place` with `value`, releasing the old one.
23///
24/// # Safety
25/// `place` is a valid slot holding a value of type `ty`, or zero.
26#[unsafe(no_mangle)]
27pub(crate) unsafe extern "C" fn nf_store(place: *mut Slot, value: Slot, ty: &TypeDesc) {
28    // SAFETY: by the caller's contract.
29    let place = unsafe { &mut *place };
30    value::release(std::mem::replace(place, value), ty);
31}