Skip to main content

EnergyHandler

Trait EnergyHandler 

pub trait EnergyHandler: Send + Sync {
    // Required methods
    fn amount(&self, host: &mut dyn ServerHost) -> u32;
    fn capacity(&self, host: &mut dyn ServerHost) -> u32;
    fn insert(
        &self,
        host: &mut dyn ServerHost,
        tx: &Transaction,
        amount: u32,
    ) -> u32;
    fn extract(
        &self,
        host: &mut dyn ServerHost,
        tx: &Transaction,
        amount: u32,
    ) -> u32;
}
Expand description

A block’s energy (NeoForge’s EnergyHandler): stateless, given the host, and written only in a transaction, as a ResourceHandler is.

Required Methods§

fn amount(&self, host: &mut dyn ServerHost) -> u32

How much it holds.

fn capacity(&self, host: &mut dyn ServerHost) -> u32

How much it holds when full.

fn insert( &self, host: &mut dyn ServerHost, tx: &Transaction, amount: u32, ) -> u32

Puts up to amount in, in transaction tx: how much went. Never more than amount.

fn extract( &self, host: &mut dyn ServerHost, tx: &Transaction, amount: u32, ) -> u32

Takes up to amount out, in transaction tx: how much came. Never more than amount.

Trait Implementations§

§

impl Wire for Box<dyn EnergyHandler>

§

const MIN: usize = 8

Minimum encoded size, used to reject impossible collection lengths.
§

fn put(&self, out: &mut Writer)

Encodes this value, recording failures on the writer.
§

fn put_owned(self, out: &mut Writer)

Consumes owned data when a resource’s ownership must cross the boundary.
§

fn take(input: &mut Reader<'_>) -> Result<Box<dyn EnergyHandler>, WireError>

Decodes one value, leaving any following bytes for the caller.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§