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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//! Handle-based FFI API for the HandleManager.
//!
//! This module provides C-compatible functions for managing expression handles.
use c_char;
use crateto_c_string;
use crateto_json_string;
use crateExpr;
use crateHANDLE_MANAGER;
/// Inserts an expression into the handle manager and returns a unique handle.
///
/// # Safety
/// The caller must ensure `expr` is a valid Expr pointer.
///
/// # Safety
///
/// This function is unsafe because it dereferences raw pointers as part of the FFI boundary.
/// The caller must ensure:
/// 1. All pointer arguments are valid and point to initialized memory.
/// 2. The memory layout of passed structures matches the expected C-ABI layout.
/// 3. Any pointers returned by this function are managed according to the API's ownership rules.
pub unsafe extern "C"
/// Retrieves an expression from the handle manager.
///
/// Returns a new owned Expr pointer that must be freed by the caller.
///
/// # Safety
/// The caller must ensure the returned pointer is freed using `rssn_free_expr`.
///
/// # Safety
///
/// This function is unsafe because it dereferences raw pointers as part of the FFI boundary.
/// The caller must ensure:
/// 1. All pointer arguments are valid and point to initialized memory.
/// 2. The memory layout of passed structures matches the expected C-ABI layout.
/// 3. Any pointers returned by this function are managed according to the API's ownership rules.
pub unsafe extern "C"
/// Checks if a handle exists in the manager.
///
/// # Safety
/// This function is safe to call with any handle value.
pub extern "C"
/// Frees a handle from the manager.
///
/// Returns true if the handle was found and freed, false otherwise.
///
/// # Safety
/// This function is safe to call with any handle value.
pub extern "C"
/// Returns the number of expressions currently managed.
///
/// # Safety
/// This function is always safe to call.
pub extern "C"
/// Clears all expressions from the handle manager.
///
/// **Warning**: This invalidates all existing handles.
///
/// # Safety
/// This function is always safe to call, but will invalidate all handles.
pub extern "C"
/// Returns a list of all active handles as a JSON array string.
///
/// The returned string must be freed using `rssn_free_string`.
///
/// # Safety
/// The caller must free the returned string.
pub extern "C"
/// Clones an expression handle, creating a new handle pointing to the same expression.
///
/// Returns 0 if the source handle doesn't exist.
///
/// # Safety
/// This function is safe to call with any handle value.
pub extern "C"
/// Converts an expression handle to a string representation.
///
/// The returned string must be freed using `rssn_free_string`.
///
/// # Safety
/// The caller must free the returned string.
pub extern "C"