Skip to content

Commit

Permalink
support bytemuck
Browse files Browse the repository at this point in the history
  • Loading branch information
dovahcrow committed Jan 15, 2024
1 parent 10ee2ee commit 0a533b6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
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

0 comments on commit 0a533b6

Please sign in to comment.