Struct Pool

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

The constant pool found in every java class file. It is used to have fast lookup for entries and small files. Removing or modifying items is not allowed to respect already ‘used’ indices or to prevent rehashing of the underlying HashMap.

A Vec and a HashMap is used internally to have fast lookups by index and value. To connect both, Rcs are used. As a result, we will have a little overhead, but this should be negligible.

Implementations§

Source§

impl Pool

Source

pub fn new() -> Self

Source

pub fn with_capacity(cap: u16) -> Self

Source

pub fn len(&self) -> u16

Returns the encoded length of the pool.

Source

pub fn is_empty(&self) -> bool

Returns true if the pool is empty, false otherwise.

Source

pub fn get(&self, index: u16) -> Result<&Item, Error>

Returns the item at a specified index. If the index is 0 or greater than the size of the pool, an error is returned.

Source

pub fn get_utf8(&self, index: u16) -> Result<String, Error>

Returns a cloned String at a specified index.

Source

pub fn get_class_name_opt(&self, index: u16) -> Result<Option<String>, Error>

Returns a class name at a specified index, but if the utf index is 0, None is returned.

Source

pub fn get_class_name(&self, index: u16) -> Result<String, Error>

Returns a class name at a specified index.

Source

pub fn push(&mut self, item: Item) -> Result<u16, Error>

Pushes an item on the pool.

Source

pub fn push_duplicate(&mut self, item: Item) -> Result<u16, Error>

Pushes an item, which might be a duplicate. This removes the possibility of reading a class, which has multiple constant pool entries, which are the same and then accessing the wrong entry.

Source

pub fn push_utf8(&mut self, content: String) -> Result<u16, Error>

Pushes a new UTF-8 item on the pool and returns an index to it.

Source

pub fn push_class(&mut self, name: String) -> Result<u16, Error>

Pushes a new class item on the pool and returns an index to it.

Source

pub fn iter(&self) -> PoolIter<'_>

Trait Implementations§

Source§

impl Default for Pool

Source§

fn default() -> Pool

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

Auto Trait Implementations§

§

impl Freeze for Pool

§

impl RefUnwindSafe for Pool

§

impl !Send for Pool

§

impl !Sync for Pool

§

impl Unpin for Pool

§

impl UnwindSafe for Pool

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.