Struct StringTable

Source
pub struct StringTable(/* private fields */);
Expand description

A table that stores NUL-terminated strings.

Always starts and ends with a NUL byte.

Implementations§

Source§

impl StringTable

Source

pub fn new() -> Self

Create an empty table.

Source

pub fn insert(&mut self, string: &CStr) -> usize

Insert new string into the table.

Does nothing if the string is already in the table.

Returns the offset at which you can find the string.

Source

pub fn get_offset(&self, string: &CStr) -> Option<usize>

Get the offset of the string in the table.

Returns None if the string isn’t present in the table.

Source

pub fn get_string(&self, offset: usize) -> Option<&CStr>

Get a reference to a string at offset.

Returns None if the offset is out-of-bounds.

Source

pub fn is_empty(&self) -> bool

Check that the table contains no strings.

Source

pub fn as_bytes(&self) -> &[u8]

Get the underlying byte slice.

The slice is never empty.

Source

pub fn into_inner(self) -> Vec<u8>

Get the underlying vector.

Source

pub fn read<R: ElfRead>(reader: &mut R, len: u64) -> Result<Self, Error>

Read the table from the reader.

Source

pub fn write<W: ElfWrite>(&self, writer: &mut W) -> Result<(), Error>

Write the table to the writer.

Trait Implementations§

Source§

impl AsRef<[u8]> for StringTable

Source§

fn as_ref(&self) -> &[u8]

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

impl BlockRead for StringTable

Source§

fn read<R: ElfRead>( reader: &mut R, _class: Class, _byte_order: ByteOrder, len: u64, ) -> Result<Self, Error>

Read the table from the reader.
Source§

impl Default for StringTable

Source§

fn default() -> Self

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

impl From<Vec<u8>> for StringTable

Source§

fn from(strings: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl<T: AsRef<CStr>> FromIterator<T> for StringTable

Source§

fn from_iter<I>(items: I) -> Self
where I: IntoIterator<Item = T>,

Creates a value from an iterator. 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> BlockWrite for T
where T: AsRef<[u8]>,

Source§

fn write<W>( &self, writer: &mut W, _class: Class, _byte_order: ByteOrder, ) -> Result<(), Error>
where W: ElfWrite,

Write the table to the writer.
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.