Skip to content

Commit 2efc352

Browse files
committed
Add from_result method to ResultType
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
1 parent a0074fe commit 2efc352

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/hyperlight_common/src/func/functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ macro_rules! impl_function {
2828
F: Fn($($P),*) -> R,
2929
($($P,)*): ParameterTuple,
3030
R: ResultType<E>,
31-
E: From<Error>,
31+
E: From<Error> + core::fmt::Debug,
3232
{
3333
fn call(&self, ($($p,)*): ($($P,)*)) -> Result<R::ReturnType, E> {
3434
(self)($($p),*).into_result()

src/hyperlight_common/src/func/ret_type.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,47 @@ macro_rules! impl_supported_return_type {
7070
}
7171

7272
/// A trait to handle either a [`SupportedReturnType`] or a [`Result<impl SupportedReturnType>`]
73-
pub trait ResultType<E> {
73+
pub trait ResultType<E: core::fmt::Debug> {
7474
/// The return type of the supported return value
7575
type ReturnType: SupportedReturnType;
7676

7777
/// Convert the return type into a `Result<impl SupportedReturnType>`
7878
fn into_result(self) -> Result<Self::ReturnType, E>;
79+
80+
/// Convert a result into this type, panicking if needed
81+
fn from_result(res: Result<Self::ReturnType, E>) -> Self;
7982
}
8083

81-
impl<T: SupportedReturnType, E> ResultType<E> for T {
84+
impl<T, E> ResultType<E> for T
85+
where
86+
T: SupportedReturnType,
87+
E: core::fmt::Debug,
88+
{
8289
type ReturnType = T;
8390

8491
fn into_result(self) -> Result<Self::ReturnType, E> {
8592
Ok(self)
8693
}
94+
95+
fn from_result(res: Result<Self::ReturnType, E>) -> Self {
96+
res.unwrap()
97+
}
8798
}
8899

89-
impl<T: SupportedReturnType, E> ResultType<E> for Result<T, E> {
100+
impl<T, E> ResultType<E> for Result<T, E>
101+
where
102+
T: SupportedReturnType,
103+
E: core::fmt::Debug,
104+
{
90105
type ReturnType = T;
91106

92107
fn into_result(self) -> Result<Self::ReturnType, E> {
93108
self
94109
}
110+
111+
fn from_result(res: Result<Self::ReturnType, E>) -> Self {
112+
res
113+
}
95114
}
96115

97116
for_each_return_type!(impl_supported_return_type);

0 commit comments

Comments
 (0)