pelf 0.1.5

A library for parsing/generating/analyzing ELF
Documentation
use super::{Elf64SectionHeader, RawElf64SectionHeader};

/// section header table.
#[derive(Default, Debug)]
pub struct Elf64SectionHeaderTable {
    /// the actual sequence of section headers.
    _headers: Vec<Elf64SectionHeader>,
}

impl Elf64SectionHeaderTable {
    /// the length of the section header table.
    pub fn len(&self) -> usize {
        self._headers.len()
    }

    /// checks the table has no entries.
    pub fn is_empty(&self) -> bool {
        self._headers.is_empty()
    }

    /// initializes a new section header table.
    pub fn new<T>(it: T) -> Self
    where
        T: IntoIterator<Item = Elf64SectionHeader>,
    {
        Self {
            _headers: it.into_iter().collect(),
        }
    }

    /// returns a program-header iterator.
    pub fn iter(&self) -> impl Iterator<Item = &Elf64SectionHeader> {
        self._headers.iter()
    }
}

impl std::iter::IntoIterator for Elf64SectionHeaderTable {
    type Item = Elf64SectionHeader;
    type IntoIter = std::vec::IntoIter<Elf64SectionHeader>;

    fn into_iter(self) -> Self::IntoIter {
        self._headers.into_iter()
    }
}

impl std::convert::From<Elf64SectionHeaderTable> for Vec<Elf64SectionHeader> {
    fn from(value: Elf64SectionHeaderTable) -> Self {
        value._headers
    }
}

impl std::convert::From<Vec<Elf64SectionHeader>> for Elf64SectionHeaderTable {
    fn from(value: Vec<Elf64SectionHeader>) -> Self {
        Self { _headers: value }
    }
}

/// the raw representation of section header table.
#[derive(Default, Debug)]
pub struct RawElf64SectionHeaderTable {
    /// the actual sequence of section headers.
    _headers: Vec<RawElf64SectionHeader>,
}

impl RawElf64SectionHeaderTable {
    /// the length of the section header table.
    pub fn len(&self) -> usize {
        self._headers.len()
    }

    /// checks the table has no entries.
    pub fn is_empty(&self) -> bool {
        self._headers.is_empty()
    }

    /// initializes a new section header table.
    pub fn new<T>(it: T) -> Self
    where
        T: IntoIterator<Item = RawElf64SectionHeader>,
    {
        Self {
            _headers: it.into_iter().collect(),
        }
    }

    /// returns a program-header iterator.
    pub fn iter(&self) -> impl Iterator<Item = &RawElf64SectionHeader> {
        self._headers.iter()
    }
}

impl std::iter::IntoIterator for RawElf64SectionHeaderTable {
    type Item = RawElf64SectionHeader;
    type IntoIter = std::vec::IntoIter<RawElf64SectionHeader>;

    fn into_iter(self) -> Self::IntoIter {
        self._headers.into_iter()
    }
}

impl std::convert::From<RawElf64SectionHeaderTable> for Vec<RawElf64SectionHeader> {
    fn from(value: RawElf64SectionHeaderTable) -> Self {
        value._headers
    }
}

impl std::convert::From<Vec<RawElf64SectionHeader>> for RawElf64SectionHeaderTable {
    fn from(value: Vec<RawElf64SectionHeader>) -> Self {
        Self { _headers: value }
    }
}