use std::fmt::Display;

use crate::error::Error;
use crate::parts::Relocatable;

#[derive(Default)]
pub struct LinkState<'a> {
    relocatables: Vec<Relocatable<'a>>,
}

impl<'a> LinkState<'a> {
    pub fn add_relocatable(&mut self, relocatable: Relocatable<'a>) -> Result<(), Error> {
        self.relocatables.push(relocatable);

        Ok(())
    }
}

impl Display for LinkState<'_> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        writeln!(f, "===Relocatables===")?;

        for r in self.relocatables.iter() {
            writeln!(f, "{}", r)?;
        }

        Ok(())
    }
}
