This commit is contained in:
Lokathor 2020-07-24 06:53:43 -06:00
parent 2d41741f40
commit 1be7a90f16
3 changed files with 15 additions and 1 deletions

View File

@ -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" }

View File

@ -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

View File

@ -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<T: Pod>(
}
/// 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`
///