#[cfg(test)]
mod tests;
mod buffer;
pub use buffer::*;
mod ptr;
pub use ptr::*;
mod vec;
pub use vec::*;
#[derive(Debug)]
pub enum Error {
IoError(std::io::Error),
OutOfBounds(usize,usize),
InvalidPointer(*const u8),
SizeMismatch(usize,usize),
SearchMatchesEverything,
AlignmentMismatch(usize, usize),
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::IoError(io) => write!(f, "i/o error: {}", io.to_string()),
Self::OutOfBounds(expected,got) => write!(f, "out of bounds: boundary is {:#x}, got {:#x} instead", expected, got),
Self::InvalidPointer(ptr) => write!(f, "invalid pointer: {:p}", ptr),
Self::SizeMismatch(expected,got) => write!(f, "size mismatch: the two types differed in size, expected {}, got {}", expected, got),
Self::SearchMatchesEverything => write!(f, "the search would match everything in the binary"),
Self::AlignmentMismatch(offset, align) => write!(f, "alignment mismatch: offset {:#x} is not aligned for type with alignment {:#x}", offset, align),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::IoError(ref e) => Some(e),
_ => None,
}
}
}
impl std::convert::From<std::io::Error> for Error {
fn from(io_err: std::io::Error) -> Self {
Self::IoError(io_err)
}
}
unsafe impl Send for Error {}
unsafe impl Sync for Error {}