Skip to content

Commit f780c6f

Browse files
committed
Avoid offset_from to keep compatibility with Rust 1.41.
1 parent 548a068 commit f780c6f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/convert.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ where
6262
let (strides, dim) = (self.npy_strides(), self.raw_dim());
6363
let orig_ptr = self.as_ptr();
6464
// Element of which size is 0 is not supported, but check it for future changes
65-
let is_empty_or_size0 = self.is_empty() || std::mem::size_of::<Self::Item>() == 0;
65+
let is_empty_or_size0 = self.is_empty() || std::mem::size_of::<A>() == 0;
6666
let vec = self.into_raw_vec();
6767
let offset = if is_empty_or_size0 {
6868
0
6969
} else {
70-
unsafe { orig_ptr.offset_from(vec.as_ptr()) as usize }
70+
(orig_ptr as usize - vec.as_ptr() as usize) / std::mem::size_of::<A>()
7171
};
7272
let mut boxed_slice = vec.into_boxed_slice();
7373
// data_ptr is not always the pointer to the 1st element.

0 commit comments

Comments
 (0)