use crate::error::Error; use std::fmt::{Display, Formatter}; pub type SectionDataIterator<'data> = Box + 'data>; pub struct SectionInfo<'data> { pub size: u64, pub data: Option>, pub offset: u64, } pub enum Section<'data> { Text(SectionInfo<'data>), Data(SectionInfo<'data>), Bss(SectionInfo<'data>), } impl Section<'_> { pub fn size(&self) -> Result { match self { Section::Text(s) => Ok(s.size), Section::Data(s) => Ok(s.size), Section::Bss(s) => Ok(s.size), } } } impl Display for SectionInfo<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!( f, "size: {}, data: {}, offset: {}", self.size, self.data.is_some(), self.offset, ) } } impl Display for Section<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { Section::Text(s) => writeln!(f, "TEXT {}", s), Section::Data(s) => writeln!(f, "DATA {}", s), Section::Bss(s) => writeln!(f, "BSS {}", s), } } }