ddex_core/
ffi.rs

1//! FFI type definitions for cross-language bindings
2
3use serde::{Deserialize, Serialize};
4
5/// Location information for FFI errors
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct FFIErrorLocation {
8    pub line: usize,
9    pub column: usize,
10    pub path: String,
11}
12
13/// FFI-safe error type for cross-language bindings
14#[derive(Debug, Clone, Serialize, Deserialize)]
15pub struct FFIError {
16    pub code: String,
17    pub message: String,
18    pub location: Option<FFIErrorLocation>,
19    pub severity: FFIErrorSeverity,
20    pub hint: Option<String>,
21    pub category: FFIErrorCategory,
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub enum FFIErrorSeverity {
26    Error,
27    Warning,
28    Info,
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
32pub enum FFIErrorCategory {
33    XmlParsing,
34    Validation,
35    Reference,
36    Version,
37    Io,
38    Internal,
39}
40
41/// Result type for FFI boundaries
42#[derive(Debug, Serialize, Deserialize)]
43pub struct FFIResult<T> {
44    pub success: bool,
45    pub data: Option<T>,
46    pub error: Option<FFIError>,
47}
48
49impl<T> FFIResult<T> {
50    pub fn ok(data: T) -> Self {
51        FFIResult {
52            success: true,
53            data: Some(data),
54            error: None,
55        }
56    }
57
58    pub fn err(error: FFIError) -> Self {
59        FFIResult {
60            success: false,
61            data: None,
62            error: Some(error),
63        }
64    }
65}
66
67/// Parse options for FFI
68#[derive(Debug, Clone, Serialize, Deserialize)]
69pub struct FFIParseOptions {
70    pub include_raw_extensions: bool,
71    pub include_comments: bool,
72    pub strict_mode: bool,
73    pub max_depth: Option<usize>,
74    pub timeout_seconds: Option<u64>,
75}
76
77impl Default for FFIParseOptions {
78    fn default() -> Self {
79        FFIParseOptions {
80            include_raw_extensions: false,
81            include_comments: false,
82            strict_mode: false,
83            max_depth: Some(100),
84            timeout_seconds: Some(30),
85        }
86    }
87}