1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use std::ffi::CString;
use std::os::raw::c_char;

use crate::macros::*;
use crate::types;

/// Return the formatted string for a DepSet object.
///
/// # Safety
/// The argument must be a non-null DepSet pointer.
#[no_mangle]
pub unsafe extern "C" fn pkgcraft_depset_str(dep: *mut types::DepSet) -> *mut c_char {
    use types::DepSet::*;
    let dep = null_ptr_check!(dep.as_ref());
    let s = match dep {
        Atom(d) => format!("{d}"),
        String(d) => format!("{d}"),
        Uri(d) => format!("{d}"),
    };
    CString::new(s).unwrap().into_raw()
}

/// Free a DepSet.
///
/// # Safety
/// The argument must be a DepSet pointer or NULL.
#[no_mangle]
pub unsafe extern "C" fn pkgcraft_depset_free(d: *mut types::DepSet) {
    if !d.is_null() {
        unsafe { drop(Box::from_raw(d)) };
    }
}