Skip to content

Commit

Permalink
strtab: document to_vec behavior; give example
Browse files Browse the repository at this point in the history
  • Loading branch information
n01e0 authored Jan 22, 2022
1 parent 6efb91c commit c7cd994
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/strtab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,24 @@ impl<'a> Strtab<'a> {
#[cfg(feature = "alloc")]
/// Converts the string table to a vector of parsed strings.
///
/// Note: This method is used to check the parsed contents of `strtab`.
/// If you want to get the correct contents of `strtab` as `Vec`, use the following example.
///
/// # Examples
/// ```rust
/// use goblin::error::Error;
///
/// pub fn show_shdr_strtab(bytes: &[u8]) -> Result<(), Error> {
/// let elf = goblin::elf::Elf::parse(&bytes)?;
///
/// for section in elf.section_headers {
/// println!("{}", elf.shdr_strtab.get_at(section.sh_name).unwrap_or(""));
/// }
///
/// Ok(())
/// }
/// ```
///
/// Requires `feature = "alloc"`
pub fn to_vec(&self) -> error::Result<Vec<&'a str>> {
// Fallback in case `Strtab` was created using `from_slice_unparsed()`.
Expand Down

0 comments on commit c7cd994

Please sign in to comment.