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
#[macro_use]
extern crate log;
use std::borrow::Cow;
use cerror::ErrorList;
fn cast_mut<'a, T>(x: *mut T) -> &'a mut T {
unsafe {
assert!(!x.is_null());
&mut (*x)
}
}
fn cast_const<'a, T>(x: *const T) -> &'a T {
unsafe {
assert!(!x.is_null(), "Object argument was null");
&(*x)
}
}
fn cstr<'a>(orig: *const libc::c_char) -> Cow<'a, str> {
unsafe {
if orig.is_null() {
Cow::from("")
} else {
std::ffi::CStr::from_ptr(orig).to_string_lossy()
}
}
}
fn map_cerr<T, E: Into<Box<dyn std::error::Error>>>(
x: Result<T, E>,
err_ptr: *mut *mut ErrorList,
) -> Option<T> {
match x {
Ok(v) => Some(v),
Err(err) => {
if !err_ptr.is_null() {
unsafe {
*err_ptr = cerror::new(err.into());
}
}
None
}
}
}
pub type Matrix<T> = Vec<Vec<T>>;
pub mod cerror;
pub mod corpusstorage;
pub mod data;
pub mod graph;
pub mod logging;
pub mod update;