1#[macro_use]
2extern crate log;
3
4use std::borrow::Cow;
5
6use cerror::ErrorList;
7
8fn cast_mut<'a, T>(x: *mut T) -> &'a mut T {
9 unsafe {
10 assert!(!x.is_null());
11 &mut (*x)
12 }
13}
14
15fn cast_const<'a, T>(x: *const T) -> &'a T {
16 unsafe {
17 assert!(!x.is_null(), "Object argument was null");
18 &(*x)
19 }
20}
21
22fn cstr<'a>(orig: *const libc::c_char) -> Cow<'a, str> {
23 unsafe {
24 if orig.is_null() {
25 Cow::from("")
26 } else {
27 std::ffi::CStr::from_ptr(orig).to_string_lossy()
28 }
29 }
30}
31
32fn map_cerr<T, E: Into<Box<dyn std::error::Error>>>(
33 x: Result<T, E>,
34 err_ptr: *mut *mut ErrorList,
35) -> Option<T> {
36 match x {
37 Ok(v) => Some(v),
38 Err(err) => {
39 if !err_ptr.is_null() {
40 unsafe {
41 *err_ptr = cerror::new(err.into());
42 }
43 }
44 None
45 }
46 }
47}
48
49pub type Matrix<T> = Vec<Vec<T>>;
51
52pub mod cerror;
53pub mod corpusstorage;
54pub mod data;
55pub mod graph;
56pub mod logging;
57pub mod update;