Skip to main content

macho_core/model/
ext.rs

1use crate::model::macho_file::MachoFile;
2
3/// Extension trait for layering domain-specific analysis on top of MachFile.
4///
5/// Extensions are transient borrowed views. Compute what you need and let them
6/// drop when the derived view is no longer needed.
7pub trait MachoExt<'data>: Sized {
8    /// The Error associated type.
9    type Error;
10
11    /// Performs parse.
12    fn parse<'mf>(macho: &'mf MachoFile<'data>) -> Result<Self, Self::Error>
13    where
14        'data: 'mf;
15}
16
17impl<'data> MachoFile<'data> {
18    /// Performs ext.
19    pub fn ext<E: MachoExt<'data>>(&self) -> Result<E, E::Error> {
20        E::parse(self)
21    }
22}