clip clip clip

This commit is contained in:
Folkert 2020-11-05 00:59:26 +01:00
parent f07e69ad87
commit 3fe0140c7e
4 changed files with 39 additions and 55 deletions

View file

@ -464,3 +464,30 @@ impl<T: Sized> Into<Result<T, &'static str>> for RocCallResult<T> {
}
}
}
impl<'a, T: Sized + Copy> Into<Result<T, &'a str>> for &'a RocCallResult<T> {
fn into(self) -> Result<T, &'a str> {
use RocCallResult::*;
match self {
Success(value) => Ok(*value),
Failure(failure) => Err({
let msg = unsafe {
let mut null_byte_index = 0;
loop {
if *failure.offset(null_byte_index) == 0 {
break;
}
null_byte_index += 1;
}
let bytes = core::slice::from_raw_parts(*failure, null_byte_index as usize);
core::str::from_utf8_unchecked(bytes)
};
msg
}),
}
}
}