pub struct PushValue {
pub value: B256,
}Expand description
Represents a value to be pushed onto the EVM stack
This type encapsulates a 32-byte value and provides methods to:
- Generate complete bytecode with optimal PUSH opcode (PUSH0-PUSH32)
- Extract just the hex data without any opcode
Fields§
§value: B256The 32-byte value to push
Implementations§
Source§impl PushValue
impl PushValue
Sourcepub fn to_hex_with_opcode(&self, evm_version: &EVMVersion) -> String
pub fn to_hex_with_opcode(&self, evm_version: &EVMVersion) -> String
Converts the PushValue to bytecode with the appropriate PUSH opcode
This generates optimal bytecode by:
- Trimming leading zeros from the value
- Selecting the smallest PUSH opcode (PUSH0-PUSH32)
- PUSH0 if the EVM version supports it and the value is zero
- Encoding the result as a hex string
Use this for normal macro/function bytecode generation.
§Examples
- Value
0x01→"6001"(PUSH1 0x01) - Value
0x00→"5f"(PUSH0, if supported by EVM version) - Value
0x123456...→"7f123456..."(PUSH32)
Sourcepub fn to_hex_trimmed(&self) -> String
pub fn to_hex_trimmed(&self) -> String
Returns the hex-encoded data without any PUSH opcode
This trims leading zeros and returns just the hex data. Use this for padding operations or when you need just the raw data without leading zeros.
§Examples
- Value
0x0000...0001→"01" - Value
0x0000...1234→"1234" - Value
0x0000...0000→""(empty string)
Sourcepub fn to_hex_full(&self) -> String
pub fn to_hex_full(&self) -> String
Returns the full 32-byte hex-encoded data without any PUSH opcode
This always returns the full 64-character hex string (32 bytes). Use this for code tables where the full 32-byte value must be preserved.
§Examples
- Value
0x0000...0001→"0000000000000000000000000000000000000000000000000000000000000001" - Value
0x0000...1234→"0000000000000000000000000000000000000000000000000000000000001234" - Value
0x0000...0000→"0000000000000000000000000000000000000000000000000000000000000000"
Sourcepub fn to_hex_full_with_opcode(&self) -> String
pub fn to_hex_full_with_opcode(&self) -> String
Converts the full 32-byte value to hex string with PUSH32 opcode prefix (0x7f).
Always generates a PUSH32 instruction (33 bytes total: 1 byte opcode + 32 bytes data), regardless of leading zeros. This is useful for operations that require exact 32-byte values on the stack, such as padding functions.
§Examples
- Value
0x0000...0001→"7f0000000000000000000000000000000000000000000000000000000000000001" - Value
0x0000...1234→"7f0000000000000000000000000000000000000000000000000000000000001234" - Value
0xFFFF...FFFF→"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
Trait Implementations§
Source§impl From<[u8; 4]> for PushValue
Convert from a 4-byte array (function/error selector) to PushValue
impl From<[u8; 4]> for PushValue
Convert from a 4-byte array (function/error selector) to PushValue
This left-pads the 4 bytes to 32 bytes (zeros on the left, data on the right)
impl StructuralPartialEq for PushValue
Auto Trait Implementations§
impl Freeze for PushValue
impl RefUnwindSafe for PushValue
impl Send for PushValue
impl Sync for PushValue
impl Unpin for PushValue
impl UnsafeUnpin for PushValue
impl UnwindSafe for PushValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<S, T> Upcast<T> for S
impl<S, T> Upcast<T> for S
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 32 bytes