diff --git a/haskell-ffi/src/to_haskell.rs b/haskell-ffi/src/to_haskell.rs index da91378..986b326 100644 --- a/haskell-ffi/src/to_haskell.rs +++ b/haskell-ffi/src/to_haskell.rs @@ -1,4 +1,5 @@ use std::{ + fmt::Display, io::{Error, Write}, marker::PhantomData, }; @@ -91,3 +92,20 @@ pub fn marshall_to_haskell_var( Err(e) => panic!("{}", e), } } + +/// Wrapper around `marshall_to_haskell_var` that calls `format` for errors +pub fn marshall_result_to_haskell_var( + res: &Result, + out: *mut u8, + out_len: &mut usize, + tag: PhantomData, +) where + T: ToHaskell, + 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); +}