123use std::{4 ffi::CString,5 os::raw::{c_char, c_double, c_int},6};78use jrsonnet_evaluator::{EvaluationState, Val};910#[no_mangle]11pub extern "C" fn jsonnet_json_extract_string(_vm: &EvaluationState, v: &Val) -> *mut c_char {12 match v {13 Val::Str(s) => CString::new(&*s as &str).unwrap().into_raw(),14 _ => std::ptr::null_mut(),15 }16}17#[no_mangle]18pub extern "C" fn jsonnet_json_extract_number(19 _vm: &EvaluationState,20 v: &Val,21 out: &mut c_double,22) -> c_int {23 match v {24 Val::Num(n) => {25 *out = *n;26 127 }28 _ => 0,29 }30}31#[no_mangle]32pub extern "C" fn jsonnet_json_extract_bool(_vm: &EvaluationState, v: &Val) -> c_int {33 match v {34 Val::Bool(false) => 0,35 Val::Bool(true) => 1,36 _ => 2,37 }38}39#[no_mangle]40pub extern "C" fn jsonnet_json_extract_null(_vm: &EvaluationState, v: &Val) -> c_int {41 match v {42 Val::Null => 1,43 _ => 0,44 }45}