Skip to content

Commit ebcd58b

Browse files
committed
Mark Element unsafe
1 parent 2cab9df commit ebcd58b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/dtype.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,15 @@ impl DataType {
169169
}
170170

171171
/// Represents that a type can be an element of `PyArray`.
172-
pub trait Element: Clone + Send {
172+
///
173+
/// A type `T` that implements this trait should be safe when managed in numpy array,
174+
/// thus implementing this trait is marked unsafe.
175+
/// For example, we don't support `PyObject` because of [an odd segfault](https://github.com/PyO3/rust-numpy/pull/143),
176+
/// although numpy itself supports it.
177+
///
178+
/// Also, we lack supports for some other types like unicode.
179+
/// If you come up with a nice implementation, we're happy to receive your PR :)
180+
pub unsafe trait Element: Clone + Send {
173181
/// `DataType` corresponding to this type.
174182
const DATA_TYPE: DataType;
175183

@@ -191,7 +199,7 @@ pub trait Element: Clone + Send {
191199

192200
macro_rules! impl_num_element {
193201
($t:ty, $npy_dat_t:ident $(,$npy_types: ident)+) => {
194-
impl Element for $t {
202+
unsafe impl Element for $t {
195203
const DATA_TYPE: DataType = DataType::$npy_dat_t;
196204
fn is_same_type(dtype: &PyArrayDescr) -> bool {
197205
$(dtype.get_typenum() == NPY_TYPES::$npy_types as i32 ||)+ false

0 commit comments

Comments
 (0)