Trevm

Struct Trevm 

Source
pub struct Trevm<Db, Insp = NoOpInspector, TrevmState = NeedsCfg>
where Db: Database, Insp: Inspector<Ctx<Db>>,
{ /* private fields */ }
Expand description

Trevm provides a type-safe interface to the EVM, using the typestate pattern.

See the crate-level documentation for more information.

Implementations§

Source§

impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
where Db: Database, Insp: Inspector<Ctx<Db>>,

Source

pub fn inner(&self) -> &Evm<Db, Insp>

Get a reference to the current Evm.

Source

pub fn inner_mut_unchecked(&mut self) -> &mut Evm<Db, Insp>

Get a mutable reference to the current Evm. This should be used with caution, as modifying the EVM may lead to inconsistent Trevmstate or invalid execution.

Source

pub fn into_inner(self) -> Box<Evm<Db, Insp>>

Destructure the Trevm into its inner EVM.

Source

pub fn into_db(self) -> Db

Deconstruct the Trevm into the backing DB, dropping all other types.

Source

pub fn inspector(&self) -> &Insp

Get a reference to the inspector.

Source

pub fn inspector_mut(&mut self) -> &mut Insp

Get a mutable reference to the inspector.

Source

pub fn replace_inspector(self, inspector: Insp) -> Self

Replace the current inspector with a new inspector of the same type.

Source

pub fn layer_inspector<Insp2>( self, inspector: Insp2, ) -> Trevm<Db, Layered<Insp2, Insp>, TrevmState>
where Insp2: Inspector<Ctx<Db>>,

Layer a new inspector on top of the current one.

Source

pub fn take_inspector(self) -> (Insp, Trevm<Db, NoOpInspector, TrevmState>)

Take the inspector out of the Trevm, replacing it with a NoOpInspector.

Source

pub fn set_inspector<Insp2>( self, inspector: Insp2, ) -> Trevm<Db, Insp2, TrevmState>
where Insp2: Inspector<Ctx<Db>>,

Replace the current inspector with a new one, dropping the old one.

Source

pub fn with_inspector<Insp2, F, NewState>( self, inspector: Insp2, f: F, ) -> Trevm<Db, Insp, NewState>
where Insp2: Inspector<Ctx<Db>>, F: FnOnce(Trevm<Db, Insp2, TrevmState>) -> Trevm<Db, Insp2, NewState>,

Run the closure with a different inspector, then restore the previous one.

Source

pub fn try_with_inspector<F, Insp2, NewState, E>( self, inspector: Insp2, f: F, ) -> Result<Trevm<Db, Insp, NewState>, EvmErrored<Db, Insp, E>>
where Insp2: Inspector<Ctx<Db>>, F: FnOnce(Trevm<Db, Insp2, TrevmState>) -> Result<Trevm<Db, Insp2, NewState>, EvmErrored<Db, Insp2, E>>,

Run a fallible function with the provided inspector, then restore the previous inspector. If the function returns an error, it will be wrapped in an EvmErrored along with the current EVM state.

Source

pub fn spec_id(&self) -> SpecId

Get the id of the currently running hardfork spec.

Source

pub fn set_spec_id(&mut self, spec_id: SpecId)

Set the SpecId, modifying the EVM handlers accordingly. This function should be called at hardfork boundaries when running multi-block trevm flows.

Source

pub fn with_spec_id<F, NewState>( self, spec_id: SpecId, f: F, ) -> Trevm<Db, Insp, NewState>
where F: FnOnce(Self) -> Trevm<Db, Insp, NewState>,

Run a closure with a different SpecId, then restore the previous setting.

Source

pub fn errored<E>(self, error: E) -> EvmErrored<Db, Insp, E>

Convert self into EvmErrored by supplying an error

Source

pub fn apply_state_overrides( self, overrides: &StateOverride, ) -> Result<Self, EVMError<<Db as Database>::Error>>
where Db: DatabaseCommit,

Apply StateOverrides to the current state. Errors if the overrides contain invalid bytecode.

Source

pub fn maybe_apply_state_overrides( self, overrides: Option<&StateOverride>, ) -> Result<Self, EVMError<<Db as Database>::Error>>
where Db: DatabaseCommit,

Apply StateOverrides to the current state, if they are provided.

Source

pub fn override_opcode( &mut self, opcode: u8, handler: Instruction<Db>, ) -> Instruction<Db>

Overide an opcode with a custom handler. Returns the previous instruction handler for the opcode.

Source

pub fn disable_opcode(&mut self, opcode: u8) -> Instruction<Db>

Disable an opcode by replacing it with unknown opcode behavior. This is a shortcut for Self::override_opcode with crate::helpers::forbidden.

Source

pub fn with_opcode_override<F, NewState>( self, opcode: u8, handler: Instruction<Db>, f: F, ) -> Trevm<Db, Insp, NewState>
where F: FnOnce(Self) -> Trevm<Db, Insp, NewState>,

Run some closure with an opcode override, then restore the previous setting.

Source

pub fn disable_prevrandao(&mut self) -> Instruction<Db>

Disable the prevrandao opcode, by replacing it with unknown opcode behavior. This is useful for block simulation, where the prevrandao opcode may produce incorrect results.

Source

pub fn enable_prevrandao(&mut self) -> Instruction<Db>

Enable the prevrandao opcode. If the prevrandao opcode was not previously disabled or replaced, this will have no effect on behavior.

Source

pub fn without_prevrandao<F, NewState>(self, f: F) -> Trevm<Db, Insp, NewState>
where F: FnOnce(Self) -> Trevm<Db, Insp, NewState>,

Run some code with the prevrandao opcode disabled, then restore the previous setting. This is useful for block simulation, where the prevrandao opcode may produce incorrect results.

Source

pub fn override_precompiles( &mut self, precompiles: EthPrecompiles, ) -> EthPrecompiles

Set the precompiles for the EVM. This will replace the current precompiles with the provided ones.

Source

pub fn with_precompiles<F, NewState>( self, precompiles: EthPrecompiles, f: F, ) -> Trevm<Db, Insp, NewState>
where F: FnOnce(Self) -> Trevm<Db, Insp, NewState>,

Run a closure with a different set of precompiles, then restore the previous setting.

Source§

impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
where Db: Database, Insp: Inspector<Ctx<Db>>,

Source

pub fn try_read_account( &mut self, address: Address, ) -> Result<Option<AccountInfo>, <Db as Database>::Error>

Get the current account info for a specific address.

Note: due to revm’s DB model, this requires a mutable pointer.

Source

pub fn try_read_nonce( &mut self, address: Address, ) -> Result<u64, <Db as Database>::Error>

Get the current nonce for a specific address

Note: due to revm’s DB model, this requires a mutable pointer.

Source

pub fn try_read_balance( &mut self, address: Address, ) -> Result<U256, <Db as Database>::Error>

Get the current nonce for a specific address

Note: due to revm’s DB model, this requires a mutable pointer.

Source

pub fn try_read_storage( &mut self, address: Address, slot: U256, ) -> Result<U256, <Db as Database>::Error>

Get the value of a storage slot.

Note: due to revm’s DB model, this requires a mutable pointer.

Source

pub fn try_read_code( &mut self, address: Address, ) -> Result<Option<Bytecode>, <Db as Database>::Error>

Get the code at the given account, if any.

Note: due to revm’s DB model, this requires a mutable pointer.

Source

pub fn try_gas_allowance( &mut self, caller: Address, gas_price: u128, ) -> Result<u64, <Db as Database>::Error>

Get the gas allowance for a specific caller and gas price.

Source§

impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
where Db: Database + DatabaseRef, Insp: Inspector<Ctx<Db>>,

Source

pub fn try_read_account_ref( &self, address: Address, ) -> Result<Option<AccountInfo>, <Db as DatabaseRef>::Error>

Get the current account info for a specific address.

Source

pub fn try_read_nonce_ref( &self, address: Address, ) -> Result<u64, <Db as DatabaseRef>::Error>

Get the current nonce for a specific address

Note: due to revm’s DB model, this requires a mutable pointer.

Source

pub fn try_read_balance_ref( &self, address: Address, ) -> Result<U256, <Db as DatabaseRef>::Error>

Get the current nonce for a specific address

Note: due to revm’s DB model, this requires a mutable pointer.

Source

pub fn try_read_storage_ref( &self, address: Address, slot: U256, ) -> Result<U256, <Db as DatabaseRef>::Error>

Get the value of a storage slot.

Source

pub fn try_read_code_ref( &self, address: Address, ) -> Result<Option<Bytecode>, <Db as DatabaseRef>::Error>

Get the code at the given account, if any.

Source

pub fn try_gas_allowance_ref( &self, caller: Address, gas_price: U256, ) -> Result<u64, <Db as DatabaseRef>::Error>

Get the gas allowance for a specific caller and gas price.

Source§

impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
where Db: Database<Error = Infallible>, Insp: Inspector<Ctx<Db>>,

Source

pub fn read_account(&mut self, address: Address) -> Option<AccountInfo>

Get the current account info for a specific address.

Note: due to revm’s DB model, this requires a mutable pointer.

Source

pub fn read_nonce(&mut self, address: Address) -> u64

Get the current nonce for a specific address

Note: due to revm’s DB model, this requires a mutable pointer.

Source

pub fn read_balance(&mut self, address: Address) -> U256

Get the current nonce for a specific address

Note: due to revm’s DB model, this requires a mutable pointer.

Source

pub fn read_storage(&mut self, address: Address, slot: U256) -> U256

Get the value of a storage slot.

Note: due to revm’s DB model, this requires a mutable pointer.

Source

pub fn read_code(&mut self, address: Address) -> Option<Bytecode>

Get the code at the given account, if any.

Note: due to revm’s DB model, this requires a mutable pointer.

Source§

impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
where Db: Database + DatabaseRef, Insp: Inspector<Ctx<Db>>,

Source

pub fn read_account_ref(&self, address: Address) -> Option<AccountInfo>

Get the current account info for a specific address.

Note: due to revm’s DB model, this requires a mutable pointer.

Source

pub fn read_nonce_ref(&self, address: Address) -> u64

Get the current nonce for a specific address

Source

pub fn read_balance_ref(&self, address: Address) -> U256

Get the current nonce for a specific address

Source

pub fn read_storage_ref(&self, address: Address, slot: U256) -> U256

Get the value of a storage slot.

Note: due to revm’s DB model, this requires a mutable pointer.

Source

pub fn read_code_ref(&self, address: Address) -> Option<Bytecode>

Get the code at the given account, if any.

Note: due to revm’s DB model, this requires a mutable pointer.

Source§

impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
where Db: Database, Insp: Inspector<Ctx<Db>>,

Source

pub fn commit_unchecked(&mut self, state: EvmState)
where Db: DatabaseCommit,

Commit a set of state changes to the database. This is a low-level API, and is not intended for general use. Regular users should prefer executing a transaction.

Source

pub fn try_modify_account_unchecked<F: FnOnce(&mut AccountInfo)>( &mut self, address: Address, f: F, ) -> Result<AccountInfo, <Db as Database>::Error>
where Db: DatabaseCommit,

Modify an account with a closure and commit the modified account. This is a low-level API, and is not intended for general use.

Source

pub fn try_set_nonce_unchecked( &mut self, address: Address, nonce: u64, ) -> Result<u64, <Db as Database>::Error>
where Db: DatabaseCommit,

Set the nonce of an account, returning the previous nonce. This is a low-level API, and is not intended for general use.

Source

pub fn try_increment_nonce_unchecked( &mut self, address: Address, ) -> Result<u64, <Db as Database>::Error>
where Db: DatabaseCommit,

Increment the nonce of an account, returning the previous nonce. This is a low-level API, and is not intended for general use.

If the nonce is already at the maximum value, it will not be incremented.

Source

pub fn try_decrement_nonce_unchecked( &mut self, address: Address, ) -> Result<u64, <Db as Database>::Error>
where Db: DatabaseCommit,

Decrement the nonce of an account, returning the previous nonce. This is a low-level API, and is not intended for general use.

If the nonce is already 0, it will not be decremented.

Source

pub fn try_set_storage_unchecked( &mut self, address: Address, slot: U256, value: U256, ) -> Result<U256, <Db as Database>::Error>
where Db: DatabaseCommit,

Set the EVM storage at a slot. This is a low-level API, and is not intended for general use.

Source

pub fn try_set_bytecode_unchecked( &mut self, address: Address, bytecode: Bytecode, ) -> Result<Option<Bytecode>, <Db as Database>::Error>
where Db: DatabaseCommit,

Set the bytecode at a specific address, returning the previous bytecode at that address. This is a low-level API, and is not intended for general use.

Source

pub fn try_increase_balance_unchecked( &mut self, address: Address, amount: U256, ) -> Result<U256, <Db as Database>::Error>
where Db: DatabaseCommit,

Increase the balance of an account. Returns the previous balance. This is a low-level API, and is not intended for general use.

If this would cause an overflow, the balance will be increased to the maximum value.

Source

pub fn try_decrease_balance_unchecked( &mut self, address: Address, amount: U256, ) -> Result<U256, <Db as Database>::Error>
where Db: DatabaseCommit,

Decrease the balance of an account. Returns the previous balance. This is a low-level API, and is not intended for general use.

If this would cause an underflow, the balance will be decreased to 0.

Source

pub fn try_set_balance_unchecked( &mut self, address: Address, amount: U256, ) -> Result<U256, <Db as Database>::Error>
where Db: DatabaseCommit,

Set the balance of an account. Returns the previous balance. This is a low-level API, and is not intended for general use.

Source§

impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
where Db: Database<Error = Infallible>, Insp: Inspector<Ctx<Db>>,

Source

pub fn modify_account_unchecked( &mut self, address: Address, f: impl FnOnce(&mut AccountInfo), ) -> AccountInfo
where Db: DatabaseCommit,

Modify an account with a closure and commit the modified account. This is a low-level API, and is not intended for general use.

Source

pub fn set_nonce_unchecked(&mut self, address: Address, nonce: u64) -> u64
where Db: DatabaseCommit,

Set the nonce of an account, returning the previous nonce. This is a low-level API, and is not intended for general use.

Source

pub fn increment_nonce_unchecked(&mut self, address: Address) -> u64
where Db: DatabaseCommit,

Increment the nonce of an account, returning the previous nonce. This is a low-level API, and is not intended for general use.

If this would cause the nonce to overflow, the nonce will be set to the maximum value.

Source

pub fn decrement_nonce_unchecked(&mut self, address: Address) -> u64
where Db: DatabaseCommit,

Decrement the nonce of an account, returning the previous nonce. This is a low-level API, and is not intended for general use.

If this would cause the nonce to underflow, the nonce will be set to 0.

Source

pub fn set_storage_unchecked( &mut self, address: Address, slot: U256, value: U256, ) -> U256
where Db: DatabaseCommit,

Set the EVM storage at a slot. This is a low-level API, and is not intended for general use.

Source

pub fn set_bytecode_unchecked( &mut self, address: Address, bytecode: Bytecode, ) -> Option<Bytecode>
where Db: DatabaseCommit,

Set the bytecode at a specific address, returning the previous bytecode at that address. This is a low-level API, and is not intended for general use.

Source

pub fn increase_balance_unchecked( &mut self, address: Address, amount: U256, ) -> U256
where Db: DatabaseCommit,

Increase the balance of an account. Returns the previous balance. This is a low-level API, and is not intended for general use.

Source

pub fn decrease_balance_unchecked( &mut self, address: Address, amount: U256, ) -> U256
where Db: DatabaseCommit,

Decrease the balance of an account. Returns the previous balance. This is a low-level API, and is not intended for general use.

Source

pub fn set_balance_unchecked(&mut self, address: Address, amount: U256) -> U256
where Db: DatabaseCommit,

Set the balance of an account. Returns the previous balance. This is a low-level API, and is not intended for general use.

Source§

impl<Db, Outer, Inner, TrevmState> Trevm<Db, Layered<Outer, Inner>, TrevmState>
where Db: Database, Outer: Inspector<Ctx<Db>>, Inner: Inspector<Ctx<Db>>,

Source

pub fn take_outer(self) -> (Outer, Trevm<Db, Inner, TrevmState>)

Remove the outer-layer inspector, leaving the inner-layer inspector in place.

Source

pub fn remove_outer(self) -> Trevm<Db, Inner, TrevmState>

Remove the outer-layer inspector, leaving the inner-layer inspector in place.

Source

pub fn take_inner(self) -> (Inner, Trevm<Db, Outer, TrevmState>)

Remove the inner-layer inspector, leaving the outer-layer inspector in place.

Source

pub fn remove_inner(self) -> Trevm<Db, Outer, TrevmState>

Remove the inner-layer inspector, leaving the outer-layer inspector in place.

Source§

impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
where Db: Database + StateAcc, Insp: Inspector<Ctx<Db>>,

Source

pub fn set_state_clear_flag(&mut self, flag: bool)

Set the [EIP-161] state clear flag, activated in the Spurious Dragon hardfork.

Source§

impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
where Db: Database + TryStateAcc, Insp: Inspector<Ctx<Db>>,

Source

pub fn try_set_state_clear_flag( &mut self, flag: bool, ) -> Result<(), <Db as TryStateAcc>::Error>

Fallibly set the [EIP-161] state clear flag, activated in the Spurious Dragon hardfork. This function is intended to be used by shared states, where mutable access may fail, e.g. an Arc<Db>.

Prefer Self::set_state_clear_flag when available.

Source§

impl<Db, Insp, E> Trevm<Db, Insp, ErroredState<E>>
where Db: Database, Insp: Inspector<Ctx<Db>>,

Source

pub const fn error(&self) -> &E

Get a reference to the error.

Source

pub fn inspect_err<F, T>(&self, f: F) -> T
where F: FnOnce(&E) -> T,

Inspect the error with a closure.

Source

pub fn discard_error(self) -> EvmNeedsTx<Db, Insp>

Discard the error and return the EVM.

Source

pub fn into_error(self) -> E

Convert the error into an EVMError.

Source

pub fn take_err(self) -> (E, EvmNeedsTx<Db, Insp>)

Reset the EVM, returning the error and the EVM ready for the next transaction.

Source

pub fn err_into<NewErr: From<E>>(self) -> EvmErrored<Db, Insp, NewErr>

Transform the error into a new error type.

Source

pub fn map_err<F, NewErr>(self, f: F) -> EvmErrored<Db, Insp, NewErr>
where F: FnOnce(E) -> NewErr,

Map the error to a new error type.

Source§

impl<Db, Insp> Trevm<Db, Insp, ErroredState<EVMError<<Db as Database>::Error>>>
where Db: Database, Insp: Inspector<Ctx<Db>>,

Source

pub const fn is_transaction_error(&self) -> bool

Check if the error is a transaction error. This is provided as a convenience function for common cases, as Transaction errors should usually be discarded.

Source

pub const fn as_transaction_error(&self) -> Option<&InvalidTransaction>

Fallible cast to a InvalidTransaction.

Source

pub fn discard_transaction_error(self) -> Result<EvmNeedsTx<Db, Insp>, Self>

Discard the error if it is a transaction error, returning the EVM. If the error is not a transaction error, return self

Source§

impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
where Db: Database, Insp: Inspector<Ctx<Db>>, TrevmState: HasBlock,

Source

pub fn block(&self) -> &BlockEnv

Get a reference to the current block environment.

Source

pub fn block_gas_limit(&self) -> u64

Get the current block gas limit.

Source

pub fn block_number(&self) -> U256

Get the current block number.

Source

pub fn block_timestamp(&self) -> U256

Get the current block timestamp.

Source

pub fn beneficiary(&self) -> Address

Get the block beneficiary address.

Source

pub fn with_block<B, F, NewState>( self, b: &B, f: F, ) -> Trevm<Db, Insp, NewState>
where B: Block, F: FnOnce(Self) -> Trevm<Db, Insp, NewState>, NewState: HasBlock,

Run a function with the provided block, then restore the previous block.

Source

pub fn try_with_block<B, F, NewState, E>( self, b: &B, f: F, ) -> Result<Trevm<Db, Insp, NewState>, EvmErrored<Db, Insp, E>>
where F: FnOnce(Self) -> Result<Trevm<Db, Insp, NewState>, EvmErrored<Db, Insp, E>>, B: Block, NewState: HasBlock,

Run a fallible function with the provided block, then restore the previous block.

Source§

impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
where Db: Database, Insp: Inspector<Ctx<Db>>, TrevmState: HasCfg,

Source

pub fn set_code_size_limit(&mut self, limit: usize) -> Option<usize>

Set the [EIP-170] contract code size limit. By default this is set to 0x6000 bytes (~25KiB). Contracts whose bytecode is larger than this limit cannot be deployed and will produce a CreateInitCodeSizeLimit error.

Source

pub fn disable_code_size_limit(&mut self) -> Option<usize>

Disable the [EIP-170] contract code size limit, returning the previous setting.

Source

pub fn without_code_size_limit<F, NewState: HasCfg>( self, f: F, ) -> Trevm<Db, Insp, NewState>
where F: FnOnce(Self) -> Trevm<Db, Insp, NewState>,

Run a closure with the code size limit disabled, then restore the previous setting.

Source

pub fn set_default_code_size_limit(&mut self) -> Option<usize>

Set the [EIP-170] contract code size limit to the default value of 0x6000 bytes (~25KiB), returning the previous setting. Contracts whose bytecode is larger than this limit cannot be deployed and will produce a CreateInitCodeSizeLimit error.

Source

pub fn disable_chain_id_check(&mut self)

Disable the [EIP-155] chain ID check.

Source

pub fn enable_chain_id_check(&mut self)

Enable the [EIP-155] chain ID check.

Source

pub fn without_chain_id_check<F, NewState: HasCfg>( self, f: F, ) -> Trevm<Db, Insp, NewState>
where F: FnOnce(Self) -> Trevm<Db, Insp, NewState>,

Run a closure with the chain ID check disabled, then restore the previous setting.

Source

pub fn with_cfg<C, F, NewState>( self, cfg: &C, f: F, ) -> Trevm<Db, Insp, NewState>
where C: Cfg, F: FnOnce(Self) -> Trevm<Db, Insp, NewState>, NewState: HasCfg,

Run a function with the provided configuration, then restore the previous configuration. This will not affect the block and tx, if those have been filled.

Source

pub fn try_with_cfg<C, F, NewState, E>( self, cfg: &C, f: F, ) -> Result<Trevm<Db, Insp, NewState>, EvmErrored<Db, Insp, E>>
where C: Cfg, F: FnOnce(Self) -> Result<Trevm<Db, Insp, NewState>, EvmErrored<Db, Insp, E>>, NewState: HasCfg,

Run a fallible function with the provided configuration, then restore the previous configuration. This will not affect the block and tx, if those have been filled.

Source

pub fn disable_eip3607(&mut self)

Available on crate feature optional_eip3607 only.

Disable EIP-3607. This allows transactions to originate from accounts that contain code. This is useful for simulating smart-contract calls.

Source

pub fn enable_eip3607(&mut self)

Available on crate feature optional_eip3607 only.
Source

pub fn without_eip3607<F, NewState: HasCfg>( self, f: F, ) -> Trevm<Db, Insp, NewState>
where F: FnOnce(Self) -> Trevm<Db, Insp, NewState>,

Available on crate feature optional_eip3607 only.

Run a closure with [EIP-3607] disabled, then restore the previous setting.

Source

pub fn disable_base_fee(&mut self)

Available on crate feature optional_no_base_fee only.

Disables EIP-1559 base fee checks. This is useful for testing method calls with zero gas price.

Source

pub fn enable_base_fee(&mut self)

Available on crate feature optional_no_base_fee only.

Enable EIP-1559 base fee checks. See Self::disable_base_fee.

Source

pub fn without_base_fee<F, NewState: HasCfg>( self, f: F, ) -> Trevm<Db, Insp, NewState>
where F: FnOnce(Self) -> Trevm<Db, Insp, NewState>,

Available on crate feature optional_no_base_fee only.

Run a closure with EIP-1559 base fee checks disabled, then restore the previous setting.

Source

pub fn disable_nonce_check(&mut self)

Disable nonce checks. This allows transactions to be sent with incorrect nonces, and is useful for things like system transactions.

Source

pub fn enable_nonce_check(&mut self)

Enable nonce checks. See Self::disable_nonce_check.

Source

pub fn without_nonce_check<F, NewState: HasCfg>( self, f: F, ) -> Trevm<Db, Insp, NewState>
where F: FnOnce(Self) -> Trevm<Db, Insp, NewState>,

Run a closure with nonce checks disabled, then restore the previous setting. This will not affect the block and tx, if those have been filled.

Source§

impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
where Db: Database, Insp: Inspector<Ctx<Db>>, TrevmState: HasTx,

Source

pub fn tx(&self) -> &TxEnv

Get a reference to the loaded tx env that will be executed.

Source

pub fn is_transfer(&self) -> bool

True if the transaction is a simple transfer.

Source

pub fn is_create(&self) -> bool

True if the transaction is a contract creation.

Source

pub fn input(&self) -> &Bytes

Get a reference to the transaction input data, which will be used as calldata or initcode during EVM execution.

Source

pub fn to(&self) -> TxKind

Read the target of the transaction.

Source

pub fn value(&self) -> U256

Read the value in wei of the transaction.

Source

pub fn gas_limit(&self) -> u64

Get the gas limit of the loaded transaction.

Source

pub fn gas_price(&self) -> u128

Get the gas price of the loaded transaction.

Source

pub fn caller(&self) -> Address

Get the address of the caller.

Source

pub fn caller_account( &mut self, ) -> Result<AccountInfo, EVMError<<Db as Database>::Error>>

Get the account of the caller. Error if the DB errors.

Source

pub fn callee(&self) -> Option<Address>

Get the address of the callee. None if Self::is_create is true.

Source

pub fn callee_account( &mut self, ) -> Result<Option<AccountInfo>, EVMError<<Db as Database>::Error>>

Get the account of the callee.

Returns as follows:

  • if Self::is_create is true, Ok(None)
  • if the callee account does not exist, Ok(AccountInfo::default())
  • if the DB errors, Err(EVMError::Database(err))
Source

pub fn callee_account_ref( &self, ) -> Result<Option<AccountInfo>, <Db as DatabaseRef>::Error>
where Db: DatabaseRef,

Get the account of the callee. None if Self::is_create is true, error if the DB errors.

Source

pub fn with_tx<T, F, NewState>(self, t: &T, f: F) -> Trevm<Db, Insp, NewState>
where T: Tx, F: FnOnce(Self) -> Trevm<Db, Insp, NewState>, NewState: HasTx,

Run a function with the provided transaction, then restore the previous transaction.

Source

pub fn try_with_tx<T, F, NewState, E>( self, t: &T, f: F, ) -> Result<Trevm<Db, Insp, NewState>, EvmErrored<Db, Insp, E>>
where T: Tx, F: FnOnce(Self) -> Result<Trevm<Db, Insp, NewState>, EvmErrored<Db, Insp, E>>, NewState: HasTx,

Run a fallible function with the provided transaction, then restore the previous transaction.

Source

pub fn caller_gas_allowance( &mut self, ) -> Result<u64, EVMError<<Db as Database>::Error>>

Return the maximum gas that the caller can purchase. This is the balance of the caller divided by the gas price.

Source

pub fn cap_tx_gas_to_allowance( &mut self, ) -> Result<u64, EVMError<<Db as Database>::Error>>

This function caps the gas limit of the transaction to the allowance of the caller.

This is useful for e.g. call simulation, where the exact amount of gas used is less important than ensuring that the call succeeds and returns a meaningful result.

§Returns

The gas limit after the operation.

Source

pub fn cap_tx_gas_to_block_limit(&mut self) -> u64

Cap the gas limit of the transaction to the minimum of the block gas limit and the transaction’s gas limit.

This is useful for ensuring that the transaction does not exceed the block gas limit, e.g. during call simulation.

§Returns

The gas limit after the operation.

Source

pub fn cap_tx_gas(&mut self) -> Result<u64, EVMError<<Db as Database>::Error>>

This function caps the gas limit of the transaction to the minimum of the block limit and the caller’s gas allowance.

This is equivalent to calling Self::cap_tx_gas_to_block_limit and Self::cap_tx_gas_to_allowance in sequence.

§Returns

The gas limit after the operation.

Source§

impl<Db, Insp> Trevm<Db, Insp, NeedsBlock>
where Db: Database, Insp: Inspector<Ctx<Db>>,

Source

pub fn drive_block<D>(self, driver: &mut D) -> DriveBlockResult<D, Db, Insp>
where D: BlockDriver<Db, Insp>, Db: DatabaseCommit,

Open a block, apply some logic, and return the EVM ready for the next block.

Source

pub fn drive_chain<D>(self, driver: &mut D) -> DriveChainResult<D, Db, Insp>
where D: ChainDriver<Db, Insp>, Db: DatabaseCommit,

Drive trevm through a set of blocks.

§Panics

If the driver contains no blocks.

Source

pub fn fill_block<B: Block>(self, filler: &B) -> EvmNeedsTx<Db, Insp>

Fill a block and return the EVM ready for a transaction.

This does not perform any pre- or post-block logic. To manage block lifecycles, use Self::drive_block or Self::drive_chain instead.

Source§

impl<Db, Insp> Trevm<Db, Insp, NeedsBlock>
where Db: Database + StateAcc, Insp: Inspector<Ctx<Db>>,

Source

pub fn finish(self) -> BundleState

Finish execution and return the outputs.

If the State has not been built with revm::database::StateBuilder::with_bundle_update then the returned BundleState will be meaningless.

See State::merge_transitions and State::take_bundle.

Source§

impl<Db, Insp> Trevm<Db, Insp, NeedsBlock>
where Db: Database + TryStateAcc, Insp: Inspector<Ctx<Db>>,

Source

pub fn try_finish( self, ) -> Result<BundleState, EvmErrored<Db, Insp, <Db as TryStateAcc>::Error>>

Fallibly finish execution and return the outputs. This function is intended to be used by shared states, where mutable access may fail, e. g. an Arc<Db>. Prefer Self::finish when available.

If the State has not been built with revm::database::StateBuilder::with_bundle_update then the returned BundleState will be meaningless.

See State::merge_transitions and State::take_bundle.

Source§

impl<Db, Insp> Trevm<Db, Insp>
where Db: Database, Insp: Inspector<Ctx<Db>>,

Source

pub fn fill_cfg<T: Cfg>(self, filler: &T) -> EvmNeedsBlock<Db, Insp>

Fill the configuration environment.

Source§

impl<Db, Insp> Trevm<Db, Insp, NeedsTx>
where Db: Database, Insp: Inspector<Ctx<Db>>,

Source

pub fn close_block(self) -> EvmNeedsBlock<Db, Insp>

Close the current block, returning the EVM ready for the next block.

Source

pub fn drive_bundle<D>(self, driver: &mut D) -> DriveBundleResult<D, Db, Insp>
where D: BundleDriver<Db, Insp>, Db: DatabaseCommit,

Drive a bundle to completion, apply some post-bundle logic, and return the EVM ready for the next bundle or tx.

Source

pub fn fill_tx<T: Tx>(self, filler: &T) -> EvmReady<Db, Insp>

Fill the transaction environment.

Source

pub fn run_tx<T: Tx>( self, filler: &T, ) -> Result<EvmTransacted<Db, Insp>, EvmErrored<Db, Insp>>

Execute a transaction. Shortcut for fill_tx(tx).run().

Source

pub fn call_tx<T: Tx>( self, filler: &T, ) -> Result<(ExecutionResult, Self), EvmErrored<Db, Insp>>

Available on crate feature call only.

Simulate the transaction, and return the ExecutionResult. The following modifications are made to the environment while simulating.

  • EIP-3607 is disabled.
  • Base fee checks are disabled.
  • Nonce checks are disabled.
Source

pub fn estimate_tx_gas<T: Tx>( self, filler: &T, ) -> Result<(EstimationResult, EvmReady<Db, Insp>), EvmErrored<Db, Insp>>

Available on crate feature estimate_gas only.

Estimate the gas cost of a transaction. Shortcut for fill_tx(tx). estimate(). Returns an EstimationResult and the EVM populated with the transaction.

Source§

impl<Db, Insp> Trevm<Db, Insp, NeedsTx>
where Db: Database + StateAcc, Insp: Inspector<Ctx<Db>>,

Source

pub fn apply_block_overrides(self, overrides: &BlockOverrides) -> Self

Apply block overrides to the current block.

Note that this is NOT reversible. The overrides are applied directly to the underlying state and these changes cannot be removed. If it is important that you have access to the pre-change state, you should wrap the existing DB in a new State and apply the overrides to that.

Source

pub fn maybe_apply_block_overrides( self, overrides: Option<&BlockOverrides>, ) -> Self

Apply block overrides to the current block, if they are provided.

Note that this is NOT reversible. The overrides are applied directly to the underlying state and these changes cannot be removed. If it is important that you have access to the pre-change state, you should wrap the existing DB in a new State and apply the overrides to that.

Source§

impl<Db, Insp> Trevm<Db, Insp, NeedsTx>
where Db: Database + TryStateAcc, Insp: Inspector<Ctx<Db>>,

Source

pub fn try_apply_block_overrides( self, overrides: &BlockOverrides, ) -> Result<Self, EvmErrored<Db, Insp, <Db as TryStateAcc>::Error>>

Apply block overrides to the current block. This function is intended to be used by shared states, where mutable access may fail, e. g. an Arc<Db>. Prefer Self::apply_block_overrides when available.

Note that this is NOT reversible. The overrides are applied directly to the underlying state and these changes cannot be removed. If it is important that you have access to the pre-change state, you should wrap the existing DB in a new State and apply the overrides to that.

Source

pub fn try_maybe_apply_block_overrides( self, overrides: Option<&BlockOverrides>, ) -> Result<Self, EvmErrored<Db, Insp, <Db as TryStateAcc>::Error>>

Apply block overrides to the current block, if they are provided. This function is intended to be used by shared states, where mutable access may fail, e.g. an Arc<Db>.Prefer Self::maybe_apply_block_overrides when available.

Note that this is NOT reversible. The overrides are applied directly to the underlying state and these changes cannot be removed. If it is important that you have access to the pre-change state, you should wrap the existing DB in a new State and apply the overrides to that.

Source§

impl<Db, Insp> Trevm<Db, Insp, Ready>
where Db: Database, Insp: Inspector<Ctx<Db>>,

Source

pub fn clear_tx(self) -> EvmNeedsTx<Db, Insp>

Clear the current transaction environment.

Source

pub fn run(self) -> Result<EvmTransacted<Db, Insp>, EvmErrored<Db, Insp>>

Execute the loaded transaction. This is a wrapper around InspectEvm::inspect_tx and produces either EvmTransacted or EvmErrored.

Source

pub fn call( self, ) -> Result<(ExecutionResult, EvmNeedsTx<Db, Insp>), EvmErrored<Db, Insp>>

Available on crate feature call only.

Simulate the transaction, and return the ExecutionResult. The following modifications are made to the environment while simulating.

  • EIP-3607 is disabled.
  • Base fee checks are disabled.
  • Nonce checks are disabled.
Source

pub fn calculate_initial_gas(&self) -> u64

Calculate the minimum gas required to start EVM execution.

This uses calculate_initial_tx_gas_for_tx to calculate the initial gas. Its output is dependent on

  • the EVM spec
  • the input data
  • whether the transaction is a contract creation or a call
  • the EIP-2930 access list
  • the number of EIP-7702 authorizations
Source

pub fn estimate_gas( self, ) -> Result<(EstimationResult, Self), EvmErrored<Db, Insp>>

Available on crate feature estimate_gas only.

Implements gas estimation. This will output an estimate of the minimum amount of gas that the transaction will consume, calculated via iterated simulation.

In the worst case this will perform a binary search, resulting in O(log(n)) simulations.

§Returns

An EstimationResult and the EVM with the transaction populated. Like with the remainder of the API, an EVM revert or an EVM halt is NOT an error. An Err is returned only if the EVM encounters a condition of use violation or a DB access fails.

§Estimation Algorithm

This function is largely based on the reth RPC estimation algorithm, which can be found here. The algorithm is as follows:

  • Disable eip-3607, allowing estimation from contract accounts.
  • Disable base fee checks.
  • Check if the transaction is a simple transfer
    • Is there input data empty? If yes, proceed to regular estimation
    • Is the callee a contract? If yes, proceed to regular estimation
    • Otherwise, shortcut return success with MIN_TRANSACTION_GAS.
  • Simulate the transaction with the maximum possible gas limit.
    • If the simulation fails, shortcut return the failure.
    • If succesful, store the gas used as the search minimum.
  • Simulate the transaction with an “optimistic” gas limit.
    • If the simulation fails, shortcut return the failure.
    • If succesful, begin the binary search around that range.
  • Binary search loop:
    • If the search range is small enough, break the loop and return the current estimate.
    • Calculate a new gas limit based on the midpoint of the search range.
    • Simulate the transaction with the new gas limit.
    • Adjust the search range based on the simulation result:
      • If the result is a success, pull the search max down to the limit.
      • If the result is a revert, push the search min up to the limit.
      • If the result is a halt, check if the halt is potentially a gas-dynamic halt.
        • If it is, treat it as a revert.
        • If it is not, shortcut return the halt.
    • Loop.
Source§

impl<Db, Insp> Trevm<Db, Insp, TransactedState>
where Db: Database, Insp: Inspector<Ctx<Db>>,

Source

pub fn result(&self) -> &ExecutionResult

Get a reference to the result.

Source

pub const fn result_mut_unchecked(&mut self) -> &mut ExecutionResult

Get a mutable reference to the result. Modification of the result is discouraged, as it may lead to inconsistent state.

This is primarily intended for use in SystemTx execution.

Source

pub const fn state(&self) -> &EvmState

Get a reference to the state.

Source

pub const fn state_mut_unchecked(&mut self) -> &mut EvmState

Get a mutable reference to the state. Modification of the state is discouraged, as it may lead to inconsistent state.

Source

pub fn result_and_state(&self) -> &ResultAndState

Get a reference to the result and state.

Source

pub const fn result_and_state_mut_unchecked(&mut self) -> &mut ResultAndState

Get a mutable reference to the result and state. Modification of the result and state is discouraged, as it may lead to inconsistent state.

This is primarily intended for use in SystemTx execution.

Source

pub fn output(&self) -> Option<&Bytes>

Get the output of the transaction. This is the return value of the outermost callframe.

Source

pub fn output_sol<T: SolCall>( &self, validate: bool, ) -> Option<Result<T::Return>>
where T::Return: SolType,

Get the output of the transaction, and decode it as the return value of a SolCall. If validate is true, the output will be type- and range-checked.

Source

pub fn gas_used(&self) -> u64

Get the gas used by the transaction.

Source

pub fn reject(self) -> EvmNeedsTx<Db, Insp>

Discard the state changes and return the EVM.

Source

pub fn into_result_and_state(self) -> ResultAndState

Take the ResultAndState and return the EVM.

Source

pub fn take_result_and_state(self) -> (ResultAndState, EvmNeedsTx<Db, Insp>)

Take the ResultAndState and return the EVM.

Source

pub fn take_result(self) -> (ExecutionResult, EvmNeedsTx<Db, Insp>)

Take the ExecutionResult, discard the EvmState and return the EVM.

Source

pub fn accept(self) -> (ExecutionResult, EvmNeedsTx<Db, Insp>)
where Db: DatabaseCommit,

Accept the state changes, commiting them to the database, and return the EVM with the ExecutionResult.

Source

pub fn try_accept( self, ) -> Result<(ExecutionResult, EvmNeedsTx<Db, Insp>), EvmErrored<Db, Insp, <Db as TryDatabaseCommit>::Error>>

Try to accept the state changes, commiting them to the database, and return the EVM with the ExecutionResult. If the commit fails, return the EVM with the error, discarding the state changes. This is a fallible version of Self::accept, intended for use with databases that can fail to commit. Prefer Self::accept when possible.

Source

pub fn accept_state(self) -> EvmNeedsTx<Db, Insp>
where Db: DatabaseCommit,

Accept the state changes, commiting them to the database, dropping the ExecutionResult.

Source

pub fn try_accept_state( self, ) -> Result<EvmNeedsTx<Db, Insp>, EvmErrored<Db, Insp, <Db as TryDatabaseCommit>::Error>>

Try to accept the state changes, commiting them to the database. If the commit fails, return the EVM with the error, discarding the state changes. This is a fallible version of Self::accept_state, intended for use with databases that can fail to commit. Prefer Self::accept_state when possible.

Source

pub fn estimation(&self) -> EstimationResult

Available on crate feature estimate_gas only.

Create an EstimationResult from the transaction ExecutionResult.

Source

pub fn take_estimation(self) -> (EstimationResult, EvmReady<Db, Insp>)

Available on crate feature estimate_gas only.

Take the EstimationResult and return it and the EVM. This discards pending state changes, but leaves the EVM ready to execute the same transaction again.

Source§

impl<Db: Database, Insp> Trevm<Db, Insp>
where Insp: InspectorWithOutput<Ctx<Db>>,

Source

pub fn take_output(&mut self) -> Insp::Output

Take the output value from the inspector.

This will also reset the output value in the inspector.

Source§

impl<Db, Insp> Trevm<Db, Insp, NeedsTx>
where Db: Database + DatabaseCommit, Insp: Inspector<Ctx<Db>>,

Source

pub fn apply_eip2935(&mut self) -> Result<(), EVMError<Db::Error>>

Apply the pre-block logic for EIP-2935. This logic was introduced in Prague and updates historical block hashes in a special system contract. Unlike other system actions, this is NOT modeled as a transaction.

Source§

impl<Db, Insp> Trevm<Db, Insp, NeedsTx>
where Db: Database + DatabaseCommit, Insp: Inspector<Ctx<Db>>,

Source

pub fn apply_eip4788( &mut self, parent_beacon_root: B256, ) -> Result<(), EVMError<Db::Error>>

Apply a system transaction as specified in EIP-4788. The EIP-4788 pre-block action was introduced in Cancun, and calls the beacon root contract to update the historical beacon root.

Source§

impl<Db, Insp> Trevm<Db, Insp, NeedsTx>
where Db: Database + DatabaseCommit, Insp: Inspector<Ctx<Db>>,

Source

pub fn apply_withdrawals<'b>( &mut self, withdrawals: impl IntoIterator<Item = &'b Withdrawal>, ) -> Result<(), EVMError<Db::Error>>

Apply the withdrawals to the EVM state.

Source§

impl<Db, Insp> Trevm<Db, Insp, NeedsTx>
where Db: Database + DatabaseCommit, Insp: Inspector<Ctx<Db>>,

Source

pub fn apply_eip7002(&mut self) -> Result<Bytes, EVMError<Db::Error>>

Apply a system transaction as specified in EIP-7002. The EIP-7002 post-block action was introduced in Prague, and calls the withdrawal request contract to accumulate withdrawal requests.

Source§

impl<Db, Insp> Trevm<Db, Insp, NeedsTx>
where Db: Database + DatabaseCommit, Insp: Inspector<Ctx<Db>>,

Source

pub fn apply_eip7251(&mut self) -> Result<Bytes, EVMError<Db::Error>>

Apply a system transaction as specified in EIP-7251. The EIP-7251 post-block action calls the consolidation request contract to process consolidation requests.

Trait Implementations§

Source§

impl<Db, Insp, TrevmState> AsRef<Evm<Context<BlockEnv, TxEnv, CfgEnv, Db>, Insp, EthInstructions<EthInterpreter, Context<BlockEnv, TxEnv, CfgEnv, Db>>, EthPrecompiles, EthFrame>> for Trevm<Db, Insp, TrevmState>
where Db: Database, Insp: Inspector<Ctx<Db>>,

Source§

fn as_ref(&self) -> &Evm<Db, Insp>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<Db, Insp, TrevmState> Debug for Trevm<Db, Insp, TrevmState>
where Db: Database, Insp: Inspector<Ctx<Db>>,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Db, Insp, TrevmState> Freeze for Trevm<Db, Insp, TrevmState>
where TrevmState: Freeze,

§

impl<Db, Insp = NoOpInspector, TrevmState = NeedsCfg> !RefUnwindSafe for Trevm<Db, Insp, TrevmState>

§

impl<Db, Insp = NoOpInspector, TrevmState = NeedsCfg> !Send for Trevm<Db, Insp, TrevmState>

§

impl<Db, Insp = NoOpInspector, TrevmState = NeedsCfg> !Sync for Trevm<Db, Insp, TrevmState>

§

impl<Db, Insp, TrevmState> Unpin for Trevm<Db, Insp, TrevmState>
where TrevmState: Unpin,

§

impl<Db, Insp = NoOpInspector, TrevmState = NeedsCfg> !UnwindSafe for Trevm<Db, Insp, TrevmState>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> FmtForward for T

Source§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
Source§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
Source§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
Source§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
Source§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
Source§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
Source§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
Source§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
Source§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pipe for T
where T: ?Sized,

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
Source§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
Source§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more