Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ readme = "README.md"
[dependencies]
bytemuck = { version = "1.15", default-features = false, features = ["derive"] }
memmap2 = { version = "0.9", optional = true }
thiserror = { version = "2.0.16", default-features = false }

[dev-dependencies]
criterion = { version = "0.5", features = ["html_reports"] }
Expand Down Expand Up @@ -49,5 +50,5 @@ harness = false
default = ["std", "mmap", "file"]
mmap = ["std", "dep:memmap2"]
file = ["std"]
std = []
std = ["thiserror/std"]
f16 = []
25 changes: 7 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,19 @@ pub use mrcfile::{MrcFile, open_file};

// Error type

#[derive(Debug)]
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("IO error")]
Io,
#[error("Invalid MRC header")]
InvalidHeader,
#[error("Invalid MRC mode")]
InvalidMode,
#[error("Invalid dimensions")]
InvalidDimensions,
#[error("Type mismatch")]
TypeMismatch,
#[cfg(feature = "mmap")]
#[error("Memory mapping error")]
Mmap,
}

impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Error::Io => write!(f, "IO error"),
Error::InvalidHeader => write!(f, "Invalid MRC header"),
Error::InvalidMode => write!(f, "Invalid MRC mode"),
Error::InvalidDimensions => write!(f, "Invalid dimensions"),
Error::TypeMismatch => write!(f, "Type mismatch"),
#[cfg(feature = "mmap")]
Error::Mmap => write!(f, "Memory mapping error"),
}
}
}

#[cfg(feature = "std")]
impl core::error::Error for Error {}