@@ -169,7 +169,19 @@ impl DataType {
169
169
}
170
170
171
171
/// Represents that a type can be an element of `PyArray`.
172
- pub trait Element : Clone + Send {
172
+ ///
173
+ /// Currently, only integer/float/complex types are supported.
174
+ /// If you come up with a nice implementation for some other types, we're happy to receive your PR :)
175
+ /// You may refer to the [numpy document](https://numpy.org/doc/stable/reference/c-api/dtype.html#enumerated-types)
176
+ /// for all types that numpy supports.
177
+ ///
178
+ /// # Safety
179
+ ///
180
+ /// A type `T` that implements this trait should be safe when managed in numpy array,
181
+ /// thus implementing this trait is marked unsafe.
182
+ /// For example, we don't support `PyObject` because of [an odd segfault](https://github.com/PyO3/rust-numpy/pull/143),
183
+ /// although numpy itself supports it.
184
+ pub unsafe trait Element : Clone + Send {
173
185
/// `DataType` corresponding to this type.
174
186
const DATA_TYPE : DataType ;
175
187
@@ -191,7 +203,7 @@ pub trait Element: Clone + Send {
191
203
192
204
macro_rules! impl_num_element {
193
205
( $t: ty, $npy_dat_t: ident $( , $npy_types: ident) +) => {
194
- impl Element for $t {
206
+ unsafe impl Element for $t {
195
207
const DATA_TYPE : DataType = DataType :: $npy_dat_t;
196
208
fn is_same_type( dtype: & PyArrayDescr ) -> bool {
197
209
$( dtype. get_typenum( ) == NPY_TYPES :: $npy_types as i32 ||) + false
0 commit comments