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

support bytemuck #635

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ rustdoc-args = ["--cfg", "docsrs"]
arbitrary = { default-features = false, optional = true, version = "1.0" }
arrayvec = { default-features = false, version = "0.7" }
borsh = { default-features = false, features = ["derive", "unstable__schema"], optional = true, version = "1.1.1" }
bytemuck = { default-features = false, optional = true, version = "1" }
bytes = { default-features = false, optional = true, version = "1.0" }
diesel1 = { default-features = false, optional = true, package = "diesel", version = "1.0" }
diesel2 = { default-features = false, optional = true, package = "diesel", version = "2.1" }
Expand Down
13 changes: 12 additions & 1 deletion src/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ use core::{
str::FromStr,
};

#[cfg(feature = "bytemuck")]
use bytemuck::{Pod, Zeroable};

// Diesel configuration
#[cfg(feature = "diesel2")]
use diesel::deserialize::FromSqlRow;
Expand Down Expand Up @@ -109,7 +112,7 @@ pub struct UnpackedDecimal {
sql_type = "Numeric"
)]
#[cfg_attr(feature = "diesel2", derive(FromSqlRow, AsExpression), diesel(sql_type = Numeric))]
#[cfg_attr(feature = "c-repr", repr(C))]
#[cfg_attr(any(feature = "c-repr", feature = "bytemuck"), repr(C))]
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshDeserialize, borsh::BorshSerialize, borsh::BorshSchema)
Expand All @@ -134,6 +137,14 @@ pub struct Decimal {
mid: u32,
}

#[cfg(feature = "bytemuck")]
#[allow(unsafe_code)]
unsafe impl Pod for Decimal {}

#[cfg(feature = "bytemuck")]
#[allow(unsafe_code)]
unsafe impl Zeroable for Decimal {}

#[cfg(feature = "ndarray")]
impl ndarray::ScalarOperand for Decimal {}

Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![doc = include_str!(concat!(env!("OUT_DIR"), "/README-lib.md"))]
#![forbid(unsafe_code)]
#![cfg_attr(not(feature = "bytemuck"), forbid(unsafe_code))]
#![cfg_attr(feature = "bytemuck", deny(unsafe_code))]
#![deny(clippy::print_stdout, clippy::print_stderr)]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
Expand Down