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

Add support for bytemuck traits #100

Merged
merged 5 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ exclude = ["/bors.toml", "/ci/*", "/.github/*"]
edition = "2018"

[package.metadata.docs.rs]
features = ["std", "serde", "rand"]
features = ["bytemuck", "std", "serde", "rand"]

[dependencies]

[dependencies.bytemuck]
optional = true
version = "1"

[dependencies.num-traits]
version = "0.2.11"
default-features = false
Expand Down
2 changes: 1 addition & 1 deletion ci/test_full.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if ! check_version $MSRV ; then
exit 1
fi

FEATURES=(libm serde)
FEATURES=(libm serde bytemuck)
cuviper marked this conversation as resolved.
Show resolved Hide resolved
check_version 1.36 && FEATURES+=(rand)
echo "Testing supported features: ${FEATURES[*]}"

Expand Down
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,18 @@ impl<T: FloatCore> Complex<T> {
}
}

/// Saftey: `Complex<T>` is `repr(C)` and contains only instances of `T`, so we
cuviper marked this conversation as resolved.
Show resolved Hide resolved
/// can guarantee it contains no *added* padding. Thus, if `T: Zeroable`,
/// `Complex<T>` is also `Zeroable`
#[cfg(feature = "bytemuck")]
unsafe impl<T: bytemuck::Zeroable> bytemuck::Zeroable for Complex<T> {}

/// Saftey: `Complex<T>` is `repr(C)` and contains only instances of `T`, so we
cuviper marked this conversation as resolved.
Show resolved Hide resolved
/// can guarantee it contains no *added* padding. Thus, if `T: Pod`,
/// `Complex<T>` is also `Pod`
#[cfg(feature = "bytemuck")]
unsafe impl<T: bytemuck::Pod> bytemuck::Pod for Complex<T> {}

impl<T: Clone + Num> From<T> for Complex<T> {
#[inline]
fn from(re: T) -> Self {
Expand Down