Introduce marshall_result_to_haskell_var
This commit is contained in:
parent
c46977354d
commit
f406ec34a3
1 changed files with 18 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
|||
use std::{
|
||||
fmt::Display,
|
||||
io::{Error, Write},
|
||||
marker::PhantomData,
|
||||
};
|
||||
|
@ -91,3 +92,20 @@ pub fn marshall_to_haskell_var<Tag, T>(
|
|||
Err(e) => panic!("{}", e),
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrapper around `marshall_to_haskell_var` that calls `format` for errors
|
||||
pub fn marshall_result_to_haskell_var<Tag, T, E>(
|
||||
res: &Result<T, E>,
|
||||
out: *mut u8,
|
||||
out_len: &mut usize,
|
||||
tag: PhantomData<Tag>,
|
||||
) where
|
||||
T: ToHaskell<Tag>,
|
||||
E: Display,
|
||||
{
|
||||
let res: Result<&T, String> = match res {
|
||||
Ok(t) => Ok(t),
|
||||
Err(e) => Err(format!("{}", e)),
|
||||
};
|
||||
marshall_to_haskell_var(&res, out, out_len, tag);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue