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

source

pub fn ok( cost: InternalGasUnits<GasCarrier>, values: SmallVec<[Value; 1]> ) -> Self

Return values of a successful execution.

source

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

source

pub fn map_partial_vm_result_empty( cost: InternalGasUnits<GasCarrier>, res: PartialVMResult<()> ) -> PartialVMResult<Self>

Convert a PartialVMResult<()> into a PartialVMResult

source

pub fn map_partial_vm_result_one( cost: InternalGasUnits<GasCarrier>, res: PartialVMResult<Value> ) -> PartialVMResult<Self>

Convert a PartialVMResult into a PartialVMResult

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V