Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
make trait unsafe to implement
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Dec 1, 2022
1 parent 0f6c841 commit c8636ee
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/array/dictionary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ use super::{new_empty_array, primitive::PrimitiveArray, Array};
use super::{new_null_array, specification::check_indexes};

/// Trait denoting [`NativeType`]s that can be used as keys of a dictionary.
pub trait DictionaryKey: NativeType + TryInto<usize> + TryFrom<usize> {
/// # Safety
///
/// Any implementation of this trait must ensure that `always_fits_usize` only
/// returns `true` if all values succeeds on `value::try_into::<usize>().unwrap()`.
pub unsafe trait DictionaryKey: NativeType + TryInto<usize> + TryFrom<usize> {
/// The corresponding [`IntegerType`] of this key
const KEY_TYPE: IntegerType;

Expand All @@ -44,40 +48,40 @@ pub trait DictionaryKey: NativeType + TryInto<usize> + TryFrom<usize> {
}
}

impl DictionaryKey for i8 {
unsafe impl DictionaryKey for i8 {
const KEY_TYPE: IntegerType = IntegerType::Int8;
}
impl DictionaryKey for i16 {
unsafe impl DictionaryKey for i16 {
const KEY_TYPE: IntegerType = IntegerType::Int16;
}
impl DictionaryKey for i32 {
unsafe impl DictionaryKey for i32 {
const KEY_TYPE: IntegerType = IntegerType::Int32;
}
impl DictionaryKey for i64 {
unsafe impl DictionaryKey for i64 {
const KEY_TYPE: IntegerType = IntegerType::Int64;
}
impl DictionaryKey for u8 {
unsafe impl DictionaryKey for u8 {
const KEY_TYPE: IntegerType = IntegerType::UInt8;

fn always_fits_usize() -> bool {
true
}
}
impl DictionaryKey for u16 {
unsafe impl DictionaryKey for u16 {
const KEY_TYPE: IntegerType = IntegerType::UInt16;

fn always_fits_usize() -> bool {
true
}
}
impl DictionaryKey for u32 {
unsafe impl DictionaryKey for u32 {
const KEY_TYPE: IntegerType = IntegerType::UInt32;

fn always_fits_usize() -> bool {
true
}
}
impl DictionaryKey for u64 {
unsafe impl DictionaryKey for u64 {
const KEY_TYPE: IntegerType = IntegerType::UInt64;

#[cfg(target_pointer_width = "64")]
Expand Down

0 comments on commit c8636ee

Please sign in to comment.