Skip to content

Commit 2067f83

Browse files
committed
Add PyArrayDescr::of<T>()
1 parent d1ca21a commit 2067f83

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/dtype.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ impl PyArrayDescr {
7575
Self::from_npy_type(py, NPY_TYPES::NPY_OBJECT)
7676
}
7777

78+
/// Returns the type descriptor for a registered type.
79+
pub fn of<T: Element>(py: Python) -> &Self {
80+
T::get_dtype(py)
81+
}
82+
7883
fn from_npy_type(py: Python, npy_type: NPY_TYPES) -> &Self {
7984
unsafe {
8085
let descr = PY_ARRAY_API.PyArray_DescrFromType(npy_type as i32);

0 commit comments

Comments
 (0)