Struct ConstantPool

Source
pub struct ConstantPool { /* private fields */ }
Expand description

A JVM constant pool. See the JVM Specification §4.4 for more information.

Implementations§

Source§

impl ConstantPool

Source

pub fn new() -> Self

Creates a new empty constant pool.

Source

pub fn with_capacity(count: u16) -> Self

Creates a new constant pool with the given capacity.

§Parameters
  • count: the maximum index of entries in the constant pool plus one.
Source

pub fn from_reader<R>(reader: &mut R, constant_pool_count: u16) -> Result<Self>
where R: Read + ?Sized,

Parses a constant pool from the given bytes.

  • constant_pool_count is the maximum index of entries in the constant pool plus one. See the JVM Specification §4.1 for more information.
§Errors

See io::Error for more information.

Source

pub fn get_entry(&self, index: u16) -> Option<&Entry>

Gets the constant pool entry at the given index.

Returns None if the index is out of bounds or the index does not point to a valid slot.

Source

pub fn put_entry(&mut self, entry: Entry) -> Result<u16, Overflow>

Put a constant pool entry to the end of the constant pool and return the index of the inserted entry.

§Errors

Returns back the entry if the constant pool is full (i.e., contains more than 65535 slots).

Source

pub fn put_entry_deduplicated( &mut self, entry: Entry, ) -> Result<(u16, bool), Overflow>

Pushes a constant pool entry to the end of the constant pool if it does not already exist.

§Return Values

Ok with a tuple indicating the index of the entry within the constant pool, and whether the entry is freshly inserted into the pool.

§Errors

Returns back the entry if the constant pool is full (i.e., contains more than 65535 slots).

Source

pub fn find<P>(&self, predicate: P) -> Option<(u16, &Entry)>
where P: Fn(&Entry) -> bool,

Finds the first constant pool entry that satisfies the given predicate.

Source

pub fn count(&self) -> u16

Gets the count of the constant pool. Note that this is NOT the number of entries. See the JVM Specification §4.1 for more information.

Trait Implementations§

Source§

impl Clone for ConstantPool

Source§

fn clone(&self) -> ConstantPool

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ConstantPool

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ConstantPool

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for ConstantPool

Source§

fn eq(&self, other: &ConstantPool) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for ConstantPool

Source§

impl StructuralPartialEq for ConstantPool

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.