Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick 0fbc928 #216

Merged
merged 1 commit into from
Aug 3, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
# versions.
toolchain: [ "msrv", "stable", "nightly" ]
target: [ "i686-unknown-linux-gnu", "x86_64-unknown-linux-gnu", "arm-unknown-linux-gnueabi", "aarch64-unknown-linux-gnu", "powerpc-unknown-linux-gnu", "powerpc64-unknown-linux-gnu", "wasm32-wasi" ]
features: [ "" , "--features __internal_use_only_features_that_work_on_stable", "--all-features" ]
features: [ "--no-default-features", "" , "--features __internal_use_only_features_that_work_on_stable", "--all-features" ]
crate: [ "zerocopy", "zerocopy-derive" ]
exclude:
# Exclude any combination which uses a non-nightly toolchain but
Expand All @@ -35,6 +35,8 @@ jobs:
features: "--all-features"
# Exclude any combination for the zerocopy-derive crate which
# uses zerocopy features.
- crate: "zerocopy-derive"
features: "--no-default-features"
- crate: "zerocopy-derive"
features: "--features __internal_use_only_features_that_work_on_stable"
- crate: "zerocopy-derive"
Expand Down Expand Up @@ -167,7 +169,7 @@ jobs:
# scope without the `alloc` feature. This isn't a big deal because we care
# primarily about `cargo doc` working for `docs.rs`, which enables the
# `alloc` feature.
if: ${{ matrix.features != '' }}
if: ${{ matrix.features != '' && matrix.features != '--no-default-features' }}

check_fmt:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pinned-stable = "1.64.0"
pinned-nightly = "nightly-2022-10-17"

[features]
default = ["byteorder"]

alloc = []
simd = []
simd-nightly = ["simd"]
Expand All @@ -43,6 +45,7 @@ zerocopy-derive = { version = "=0.6.1", path = "zerocopy-derive" }
[dependencies.byteorder]
version = "1.3"
default-features = false
optional = true

[dev-dependencies]
rand = "0.6"
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ types, see the `byteorder` module.
enabled, the `alloc` crate is added as a dependency, and some
allocation-related functionality is added.

`byteorder` (enabled by default): Adds the `byteorder` module and a
dependency on the `byteorder` crate. The `byteorder` module provides byte
order-aware equivalents of the multi-byte primitive numerical types. Unlike
their primitive equivalents, the types in this module have no alignment
requirement and support byte order conversions. This can be useful in
handling file formats, network packet layouts, etc which don't provide
alignment guarantees and which may use a byte order different from that of
the execution platform.

`simd`: When the `simd` feature is enabled, `FromBytes` and `AsBytes` impls
are emitted for all stable SIMD types which exist on the target platform.
Note that the layout of SIMD types is not yet stabilized, so these impls may
Expand Down
15 changes: 13 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@
//! enabled, the `alloc` crate is added as a dependency, and some
//! allocation-related functionality is added.
//!
//! `byteorder` (enabled by default): Adds the [`byteorder`] module and a
//! dependency on the `byteorder` crate. The `byteorder` module provides byte
//! order-aware equivalents of the multi-byte primitive numerical types. Unlike
//! their primitive equivalents, the types in this module have no alignment
//! requirement and support byte order conversions. This can be useful in
//! handling file formats, network packet layouts, etc which don't provide
//! alignment guarantees and which may use a byte order different from that of
//! the execution platform.
//!
//! `simd`: When the `simd` feature is enabled, `FromBytes` and `AsBytes` impls
//! are emitted for all stable SIMD types which exist on the target platform.
//! Note that the layout of SIMD types is not yet stabilized, so these impls may
Expand Down Expand Up @@ -121,10 +130,12 @@
#![cfg_attr(not(test), no_std)]
#![cfg_attr(feature = "simd-nightly", feature(stdsimd))]

#[cfg(feature = "byteorder")]
pub mod byteorder;
#[doc(hidden)]
pub mod derive_util;

#[cfg(feature = "byteorder")]
pub use crate::byteorder::*;
pub use zerocopy_derive::*;

Expand Down Expand Up @@ -2856,7 +2867,7 @@ pub use alloc_support::*;
mod tests {
#![allow(clippy::unreadable_literal)]

use core::{convert::TryInto, ops::Deref};
use core::ops::Deref;

use static_assertions::assert_impl_all;

Expand Down Expand Up @@ -2918,7 +2929,7 @@ mod tests {

// Converts an `AU64` to bytes using this platform's endianness.
fn au64_to_bytes(u: AU64) -> [u8; 8] {
U64::<NativeEndian>::new(u.0).as_bytes().try_into().unwrap()
transmute!(u)
}

// An unsized type.
Expand Down