Skip to content

Commit

Permalink
Closes #22
Browse files Browse the repository at this point in the history
  • Loading branch information
Lokathor committed Jul 24, 2020
1 parent 2d41741 commit 1be7a90
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 11 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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.
Expand All @@ -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`
///
Expand Down

0 comments on commit 1be7a90

Please sign in to comment.