Merge pull request #1 from BeFunctional/edsko/marshall-result
Introduce `marshall_result_to_haskell_var`
This commit is contained in:
commit
f034cbe5d9
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