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

Remove remaining unsafe from kv module #596

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ std = []

# requires the latest stable
# this will have a tighter MSRV before stabilization
kv_unstable = ["value-bag"]
kv_unstable = ["value-bag", "zerocopy"]
kv_unstable_sval = ["kv_unstable", "value-bag/sval", "sval", "sval_ref"]
kv_unstable_std = ["std", "kv_unstable", "value-bag/error"]
kv_unstable_serde = ["kv_unstable_std", "value-bag/serde", "serde"]
Expand All @@ -58,6 +58,7 @@ serde = { version = "1.0", optional = true, default-features = false }
sval = { version = "2.1", optional = true, default-features = false }
sval_ref = { version = "2.1", optional = true, default-features = false }
value-bag = { version = "1.4", optional = true, default-features = false }
zerocopy = { version = "0.7.19", optional = true, default-features = false }

[dev-dependencies]
serde = { version = "1.0", features = ["derive"] }
Expand Down
6 changes: 2 additions & 4 deletions src/kv/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,13 @@ impl<'v> From<&'v i128> for Value<'v> {

impl<'v> From<&'v std::num::NonZeroU128> for Value<'v> {
fn from(v: &'v std::num::NonZeroU128) -> Value<'v> {
// SAFETY: `NonZeroU128` and `u128` have the same ABI
Value::from_value_bag(unsafe { &*(v as *const std::num::NonZeroU128 as *const u128) })
Value::from_value_bag::<&'v u128>(zerocopy::transmute_ref!(v))
}
}

impl<'v> From<&'v std::num::NonZeroI128> for Value<'v> {
fn from(v: &'v std::num::NonZeroI128) -> Value<'v> {
// SAFETY: `NonZeroI128` and `i128` have the same ABI
Value::from_value_bag(unsafe { &*(v as *const std::num::NonZeroI128 as *const i128) })
Value::from_value_bag::<&'v i128>(zerocopy::transmute_ref!(v))
}
}

Expand Down