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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (C) 2020 - 2022, J2 Innovations
//!
//! C API for working with the [XStr](crate::val::XStr) type.
//!
use ;
use CString;
use c_char;
use crateValue;
/// Get the characters of a [XStr](crate::val::XStr) [Value](crate::val::Value) type
/// # Arguments
/// val A [XStr](crate::val::XStr) [Value](crate::val::Value) to get the C string from.
/// # Returns
/// The C string or `null` if there was an error, in which case the [last_error_message](super::err::last_error_message)
/// can be called to get the error message.
/// # Example
/// ```rust
/// # use crate::libhaystack::val::Value;
/// # use crate::libhaystack::c_api::value::*;
/// # use crate::libhaystack::c_api::xstr::*;
/// # unsafe {
/// let name = std::ffi::CString::new("Type").unwrap();
/// let data = std::ffi::CString::new("data").unwrap();
/// let val = haystack_value_make_xstr(name.as_ptr(), data.as_ptr());
/// # let val = Box::<Value>::leak(val.unwrap());
/// let res = haystack_value_get_xstr_type(val) as *mut i8;
/// assert_eq!(std::ffi::CString::from_raw(res), name);
/// # }
/// ```
/// # Safety
/// Panics on invalid input data
pub unsafe extern "C"
/// Get the characters of a [XStr](crate::val::XStr) [Value](crate::val::Value)
/// # Arguments
/// val A [XStr](crate::val::XStr) [Value](crate::val::Value) to get the C string from.
/// # Returns
/// The C string or `null` if there was an error, in which case the [last_error_message](super::err::last_error_message)
/// can be called to get the error message.
/// # Example
/// ```rust
/// # use crate::libhaystack::val::Value;
/// # use crate::libhaystack::c_api::value::*;
/// # use crate::libhaystack::c_api::xstr::*;
/// # unsafe {
/// let name = std::ffi::CString::new("Type").unwrap();
/// let data = std::ffi::CString::new("data").unwrap();
/// let val = haystack_value_make_xstr(name.as_ptr(), data.as_ptr());
/// # let val = Box::<Value>::leak(val.unwrap());
/// let res = haystack_value_get_xstr_value(val) as *mut i8;
/// assert_eq!(std::ffi::CString::from_raw(res), data);
/// # }
/// ```
/// # Safety
/// Panics on invalid input data
pub unsafe extern "C"