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
use dsnp_graph_config::errors::DsnpGraphError;

// Opaque handle for DsnpGraphError
pub struct GraphError {
	// to make errors opaque this field must be private
	// it enables to create a pointer to the error
	error: *mut DsnpGraphError,
}

impl GraphError {
	pub fn from_error(error: DsnpGraphError) -> *mut Self {
		// allocate memory for the error
		let mut error_handle = Box::new(Self { error: std::ptr::null_mut() });

		// allocate memory for the error
		error_handle.error = Box::into_raw(Box::new(error));

		// return a pointer to the error
		Box::into_raw(error_handle)
	}

	pub fn error_code(&self) -> i32 {
		unsafe { (*self.error).error_code() }
	}

	pub fn error_message(&self) -> String {
		unsafe { (*self.error).to_string() }
	}
}