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
use Future;
use ;
use ;
use debug;
use Error as TError;
use Error as JError;
//use crate::context::TesseractContext;
/*pub fn tesseractify<T, I, F>(env: &JNIEnv, fun: F) -> tesseract::Result<T>
where
I: Into<T>,
F: FnOnce() -> jni::errors::Result<I>,
{
match fun() {
Err(jni::errors::Error::JavaException) => {
let tesseract_error = tesseractify_no_exception( || {
let exception = env.exception_occurred()?;
env.exception_clear()?;
tesseractify_exception(env, exception)
})?;
Err(tesseract_error)
}
other => {
tesseractify_no_exception(|| {other})
}
}
}
pub fn tesseractify_global_result<T>(result: GlobalResult<T>) -> tesseract::Result<T> {
match result {
Ok(ok) => Ok(ok),
Err(error) => {
Err(match error {
GlobalError::JniError(error) => tesseractify_jni_error(error),
GlobalError::Exception(exception) => {
exception.do_in_tesseract_context(10, |env, exception| {
let throwable = JThrowable::from(exception);
tesseractify_exception(&env, throwable)
})?
}
})
}
}
}
pub async fn tesseractify_async<T, F>(fun: impl FnOnce() -> F) -> tesseract::Result<T>
where F: Future<Output = GlobalResult<T>>, {
match fun().await {
Ok(ok) => Ok(ok),
Err(error) => {
Err(match error {
GlobalError::JniError(error) => tesseractify_jni_error(error),
GlobalError::Exception(exception) => {
exception.do_in_tesseract_context(10, |env, exception| {
let throwable = JThrowable::from(exception);
tesseractify_exception(&env, throwable)
})?
}
})
}
}
}
*/