@@ -14,12 +14,13 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17- use hyperlight_common:: flatbuffer_wrappers:: function_types:: { ParameterType , ParameterValue } ;
18- use tracing:: { Span , instrument} ;
17+ use alloc:: string:: String ;
18+ use alloc:: vec;
19+ use alloc:: vec:: Vec ;
1920
21+ use super :: error:: Error ;
2022use super :: utils:: for_each_tuple;
21- use crate :: HyperlightError :: { ParameterValueConversionFailure , UnexpectedNoOfArguments } ;
22- use crate :: { Result , log_then_return} ;
23+ use crate :: flatbuffer_wrappers:: function_types:: { ParameterType , ParameterValue } ;
2324
2425/// This is a marker trait that is used to indicate that a type is a
2526/// valid Hyperlight parameter type.
@@ -34,7 +35,7 @@ pub trait SupportedParameterType: Sized + Clone + Send + Sync + 'static {
3435 /// `SupportedParameterType`
3536 fn into_value ( self ) -> ParameterValue ;
3637 /// Get the actual inner value of this `SupportedParameterType`
37- fn from_value ( value : ParameterValue ) -> Result < Self > ;
38+ fn from_value ( value : ParameterValue ) -> Result < Self , Error > ;
3839}
3940
4041// We can then implement these traits for each type that Hyperlight supports as a parameter or return type
@@ -57,21 +58,17 @@ macro_rules! impl_supported_param_type {
5758 impl SupportedParameterType for $type {
5859 const TYPE : ParameterType = ParameterType :: $enum;
5960
60- #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
6161 fn into_value( self ) -> ParameterValue {
6262 ParameterValue :: $enum( self )
6363 }
6464
65- #[ instrument( err( Debug ) , skip_all, parent = Span :: current( ) , level= "Trace" ) ]
66- fn from_value( value: ParameterValue ) -> Result <Self > {
65+ fn from_value( value: ParameterValue ) -> Result <Self , Error > {
6766 match value {
6867 ParameterValue :: $enum( i) => Ok ( i) ,
69- other => {
70- log_then_return!( ParameterValueConversionFailure (
71- other. clone( ) ,
72- stringify!( $type)
73- ) ) ;
74- }
68+ other => Err ( Error :: ParameterValueConversionFailure (
69+ other. clone( ) ,
70+ stringify!( $type) ,
71+ ) ) ,
7572 }
7673 }
7774 }
@@ -93,26 +90,22 @@ pub trait ParameterTuple: Sized + Clone + Send + Sync + 'static {
9390 fn into_value ( self ) -> Vec < ParameterValue > ;
9491
9592 /// Get the actual inner value of this `SupportedParameterType`
96- fn from_value ( value : Vec < ParameterValue > ) -> Result < Self > ;
93+ fn from_value ( value : Vec < ParameterValue > ) -> Result < Self , Error > ;
9794}
9895
9996impl < T : SupportedParameterType > ParameterTuple for T {
10097 const SIZE : usize = 1 ;
10198
10299 const TYPE : & [ ParameterType ] = & [ T :: TYPE ] ;
103100
104- #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
105101 fn into_value ( self ) -> Vec < ParameterValue > {
106102 vec ! [ self . into_value( ) ]
107103 }
108104
109- #[ instrument( err( Debug ) , skip_all, parent = Span :: current( ) , level= "Trace" ) ]
110- fn from_value ( value : Vec < ParameterValue > ) -> Result < Self > {
105+ fn from_value ( value : Vec < ParameterValue > ) -> Result < Self , Error > {
111106 match <[ ParameterValue ; 1 ] >:: try_from ( value) {
112107 Ok ( [ val] ) => Ok ( T :: from_value ( val) ?) ,
113- Err ( value) => {
114- log_then_return ! ( UnexpectedNoOfArguments ( value. len( ) , 1 ) ) ;
115- }
108+ Err ( value) => Err ( Error :: UnexpectedNoOfArguments ( value. len ( ) , 1 ) ) ,
116109 }
117110 }
118111}
@@ -126,17 +119,15 @@ macro_rules! impl_param_tuple {
126119 $( $param:: TYPE ) ,*
127120 ] ;
128121
129- #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
130122 fn into_value( self ) -> Vec <ParameterValue > {
131123 let ( $( $name, ) * ) = self ;
132124 vec![ $( $name. into_value( ) ) ,* ]
133125 }
134126
135- #[ instrument( err( Debug ) , skip_all, parent = Span :: current( ) , level= "Trace" ) ]
136- fn from_value( value: Vec <ParameterValue >) -> Result <Self > {
127+ fn from_value( value: Vec <ParameterValue >) -> Result <Self , Error > {
137128 match <[ ParameterValue ; $N] >:: try_from( value) {
138129 Ok ( [ $( $name, ) * ] ) => Ok ( ( $( $param:: from_value( $name) ?, ) * ) ) ,
139- Err ( value) => { log_then_return! ( UnexpectedNoOfArguments ( value. len( ) , $N) ) ; }
130+ Err ( value) => Err ( Error :: UnexpectedNoOfArguments ( value. len( ) , $N) )
140131 }
141132 }
142133 }
0 commit comments