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
// Copyright (C) 2020 - 2022, J2 Innovations
//!
//! C API for working with the [Symbol](crate::val::Symbol) type.
//!
use ;
use CString;
use c_char;
use crateValue;
/// Get number of character, without trailing zero, of a [Symbol](crate::val::Symbol) [Value](crate::val::Value)
/// # Arguments
/// val A [Symbol](crate::val::Symbol) [Value](crate::val::Value) to get the len from
/// # Returns
/// - the size of the string
/// - -1 (usize::MAX) if there was an error getting the string length
/// # Example
/// ```rust
/// # use crate::libhaystack::val::Value;
/// # use crate::libhaystack::c_api::value::*;
/// # use crate::libhaystack::c_api::symbol::*;
/// # unsafe {
/// let symbol = std::ffi::CString::new("symbol").unwrap();
/// let val = haystack_value_make_symbol(symbol.as_ptr());
/// # let val = Box::<Value>::leak(val.unwrap());
/// assert!(haystack_value_is_symbol(val));
/// assert_eq!(haystack_value_get_symbol_value_len(val), 6);
/// # }
/// ```
/// # Safety
/// Panics on invalid input data
pub unsafe extern "C"
/// Get the character of a [Symbol](crate::val::Symbol) [Value](crate::val::Value)
/// # Arguments
/// val A [Symbol](crate::val::Symbol) [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::symbol::*;
/// # unsafe {
/// let symbol = std::ffi::CString::new("symbol").unwrap();
/// let val = haystack_value_make_symbol(symbol.as_ptr());
/// # let val = Box::<Value>::leak(val.unwrap());
/// let res = haystack_value_get_symbol_value(val) as *mut i8;
/// assert_eq!(std::ffi::CString::from_raw(res), symbol);
/// # }
/// ```
/// # Safety
/// Panics on invalid input data
pub unsafe extern "C"