diff --git a/Cargo.toml b/Cargo.toml index 0aa5a0cd..4366e224 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,9 @@ exclude = ["/scripts/*", "/.travis.yml", "/appveyor.yml", "/bors.toml", "/pedant all-features = true [features] +# Note: Yeah these names are non-standard, we'll fix it in v2 some day maybe extern_crate_alloc = [] +extern_crate_std = ["extern_crate_alloc"] [badges] appveyor = { repository = "Lokathor/bytemuck" } diff --git a/changelog.md b/changelog.md index 44a20ca5..01a9cc9d 100644 --- a/changelog.md +++ b/changelog.md @@ -8,6 +8,8 @@ * The `offset_of!` macro now supports a 2-arg version. For types that impl Default, it'll just make an instance using `default` and then call over to the 3-arg version. +* The `PodCastError` type now supports `Hash` and `Display`. Also if you enable + the `extern_crate_std` feature then it will support `std::error::Error`. ## 1.2.0 diff --git a/src/lib.rs b/src/lib.rs index a90199d5..f21c0b26 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -56,6 +56,9 @@ macro_rules! impl_unsafe_marker_for_array { } } +#[cfg(feature = "extern_crate_std")] +extern crate std; + #[cfg(feature = "extern_crate_alloc")] extern crate alloc; #[cfg(feature = "extern_crate_alloc")] @@ -187,7 +190,7 @@ pub fn try_from_bytes_mut( } /// The things that can go wrong when casting between [`Pod`] data forms. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum PodCastError { /// You tried to cast a slice to an element type with a higher alignment /// requirement but the slice wasn't aligned. @@ -204,6 +207,13 @@ pub enum PodCastError { /// were not so now you're sad. AlignmentMismatch, } +impl core::fmt::Display for PodCastError { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "{:?}", self) + } +} +#[cfg(feature = "extern_crate_std")] +impl std::error::Error for PodCastError {} /// Cast `T` into `U` ///