Struct move_vm_types::natives::function::NativeResult
source · pub struct NativeResult {
pub cost: InternalGasUnits<GasCarrier>,
pub result: Result<SmallVec<[Value; 1]>, u64>,
}
Expand description
Result of a native function execution requires charges for execution cost.
An execution that causes an invariant violation would not return a NativeResult
but
return a PartialVMError
error directly.
All native functions must return a PartialVMResult<NativeResult>
where an Err
is returned
when an error condition is met that should not charge for the execution. A common example
is a VM invariant violation which should have been forbidden by the verifier.
Errors (typically user errors and aborts) that are logically part of the function execution
must be expressed in a NativeResult
with a cost and a VMStatus.
Fields§
§cost: InternalGasUnits<GasCarrier>
The cost for running that function, whether successfully or not.
result: Result<SmallVec<[Value; 1]>, u64>
Result of execution. This is either the return values or the error to report.
Implementations§
source§impl NativeResult
impl NativeResult
sourcepub fn ok(
cost: InternalGasUnits<GasCarrier>,
values: SmallVec<[Value; 1]>
) -> Self
pub fn ok( cost: InternalGasUnits<GasCarrier>, values: SmallVec<[Value; 1]> ) -> Self
Return values of a successful execution.
sourcepub fn err(cost: InternalGasUnits<GasCarrier>, abort_code: u64) -> Self
pub fn err(cost: InternalGasUnits<GasCarrier>, abort_code: u64) -> Self
Failed execution. The failure is a runtime failure in the function and not an invariant
failure of the VM which would raise a PartialVMError
error directly.
The only thing the funciton can specify is its abort code, as if it had invoked the Abort
bytecode instruction
sourcepub fn map_partial_vm_result_empty(
cost: InternalGasUnits<GasCarrier>,
res: PartialVMResult<()>
) -> PartialVMResult<Self>
pub fn map_partial_vm_result_empty( cost: InternalGasUnits<GasCarrier>, res: PartialVMResult<()> ) -> PartialVMResult<Self>
Convert a PartialVMResult<()> into a PartialVMResult
sourcepub fn map_partial_vm_result_one(
cost: InternalGasUnits<GasCarrier>,
res: PartialVMResult<Value>
) -> PartialVMResult<Self>
pub fn map_partial_vm_result_one( cost: InternalGasUnits<GasCarrier>, res: PartialVMResult<Value> ) -> PartialVMResult<Self>
Convert a PartialVMResult