Skip to main content

ConstantPoolBuilder

Struct ConstantPoolBuilder 

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

A builder for the constant pool of a class.

This struct manages the deduplication of constant pool entries, ensuring that strings, classes, and member references are stored efficiently.

Implementations§

Source§

impl ConstantPoolBuilder

Source

pub fn new() -> Self

Creates a new, empty ConstantPoolBuilder.

The constant pool starts with a dummy entry at index 0, as per JVM spec.

Source

pub fn into_pool(self) -> Vec<CpInfo>

Consumes the builder and returns the raw vector of CpInfo entries.

Source

pub fn utf8(&mut self, value: &str) -> u16

Adds a UTF-8 string to the constant pool if it doesn’t exist.

Returns the index of the entry.

Source

pub fn class(&mut self, name: &str) -> u16

Adds a Class constant to the pool.

This will recursively add the UTF-8 name of the class.

Source

pub fn string(&mut self, value: &str) -> u16

Adds a String constant to the pool.

This is for string literals (e.g., ldc "foo").

Source

pub fn integer(&mut self, value: i32) -> u16

Source

pub fn float(&mut self, value: f32) -> u16

Source

pub fn long(&mut self, value: i64) -> u16

Source

pub fn double(&mut self, value: f64) -> u16

Source

pub fn name_and_type(&mut self, name: &str, descriptor: &str) -> u16

Adds a NameAndType constant to the pool.

Used for field and method descriptors.

Source

pub fn field_ref(&mut self, owner: &str, name: &str, descriptor: &str) -> u16

Adds a Fieldref constant to the pool.

Source

pub fn method_ref(&mut self, owner: &str, name: &str, descriptor: &str) -> u16

Adds a Methodref constant to the pool.

Trait Implementations§

Source§

impl Debug for ConstantPoolBuilder

Source§

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

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

impl Default for ConstantPoolBuilder

Source§

fn default() -> ConstantPoolBuilder

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

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> 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, 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.