WIP
parent
77b97859df
commit
e52e3a2761
@ -1,15 +1,15 @@
|
|||||||
use std::fmt::Display;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use std::{convert::TryFrom, fmt::Display, path::PathBuf};
|
||||||
|
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
|
|
||||||
use super::Section;
|
use super::Section;
|
||||||
|
|
||||||
pub type BSI<'data> = Box<dyn Iterator<Item = Result<Section<'data>, Error>> + 'data>;
|
pub type BSI<'iter, 'data> = Box<dyn Iterator<Item = Result<Section<'data>, Error>> + 'iter>;
|
||||||
/// Contains all the needed getters to construct a final
|
/// Contains all the needed getters to construct a final
|
||||||
/// mushed and relocated executable from an object file
|
/// mushed and relocated executable from an object file
|
||||||
pub trait Relocatable: Display {
|
pub trait Relocatable<'data>: Display + TryFrom<PathBuf, Error = Error> {
|
||||||
fn origin(&self) -> &Path; // not same as section's path since this one's supposed to be cannonical
|
fn origin(&self) -> &Path; // not same as section's path since this one's supposed to be cannonical
|
||||||
|
|
||||||
fn sections(&self) -> BSI<'_>;
|
fn sections<'sections>(self: &'sections Self) -> BSI<'sections, 'data>;
|
||||||
}
|
}
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
use std::path::PathBuf;
|
|
||||||
use std::{fs::canonicalize, io::ErrorKind};
|
|
||||||
|
|
||||||
use crate::error::Error;
|
|
||||||
|
|
||||||
pub struct Storage {
|
|
||||||
origin: PathBuf,
|
|
||||||
bytes: Vec<u8>, // for storing the total if needed
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Storage {
|
|
||||||
pub fn new(origin: PathBuf) -> Self {
|
|
||||||
Self {
|
|
||||||
origin,
|
|
||||||
bytes: Vec::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn origin(&self) -> Result<PathBuf, Error> {
|
|
||||||
canonicalize(&self.origin).map_err(|e| e.into())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn destination(&self) -> Result<PathBuf, Error> {
|
|
||||||
let mut dest = canonicalize(&self.origin)?;
|
|
||||||
if !dest.pop() {
|
|
||||||
let err = std::io::Error::new(ErrorKind::Other, "Destination path invalid");
|
|
||||||
Err(Error::IOError(Box::new(err)))
|
|
||||||
} else {
|
|
||||||
dest.push("rld.out");
|
|
||||||
Ok(dest)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn iter(&mut self) -> Result<impl Iterator<Item = &u8>, Error> {
|
|
||||||
self.bytes = std::fs::read(&self.origin)?;
|
|
||||||
|
|
||||||
Ok(self.bytes.iter())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn bytes(&mut self) -> Result<&[u8], Error> {
|
|
||||||
self.bytes = std::fs::read(&self.origin)?;
|
|
||||||
|
|
||||||
Ok(&self.bytes)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue