fix(rust): fix no_std compilation due to ockam::node attribute #2355
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While working in #2213 I found that the compilation of
no_std
examples were failing due to problems with theockam::node
attributeCurrent Behaviour
When doing:
I got the error:
The same happened when running the example with any of the feature flags corresponding to
no_std
Proposed Changes
The reason for this is that the
node
attribute returns the result fromExecutor::execute
and it eitherunwraps
the result or attach a?
depending on the return type ofmain
.This works well for std where the return type of
execute
isResult<F::Output>
whereF::Output
is the return type ofmain
, so if the return type ofmain
isResult<()>
the return type ofexecute
isResult<Result<()>>
and applying the?
operator we get aResult<()>
.However, for no_std the return type of
execute
isResult<()>
so applying the?
operator toResult<()>
we get a()
which doesn't match with the return type of a mainResult<()>
, so in theno_std
case I simply changed it to let the attribute return the result fromexecute
verbatim.This also means that
Ockam::node
in no_std will only work with no return type orResult<()>
but since there is a TODO forexecute
to be unified with the std case that'll be solved, there's also no option to make it compatible with any other return type since theexecute
function as is now consume any type returned frommain
by unwrapping it and returningOk(())
Checks