diff rust/hg-cpython/src/dirstate/dirstate_map.rs @ 42799:5399532510ae

rust: simply use TryInto to convert slice to array Since our rust module depends on TryInto, there's no point to avoid using it. While rewriting copy_into_array(), I noticed CPython interface doesn't check the length of the p1/p2 values, which is marked as TODO.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 17 Aug 2019 11:37:42 +0900
parents 4e8f504424f3
children 79561843729a
line wrap: on
line diff
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs	Sat Aug 17 13:55:05 2019 +0900
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs	Sat Aug 17 11:37:42 2019 +0900
@@ -24,7 +24,7 @@
     ref_sharing::PySharedState,
 };
 use hg::{
-    utils::copy_into_array, DirsIterable, DirsMultiset, DirstateEntry,
+    DirsIterable, DirsMultiset, DirstateEntry,
     DirstateMap as RustDirstateMap, DirstateParents, DirstateParseError,
     EntryState,
 };
@@ -239,8 +239,9 @@
     }
 
     def setparents(&self, p1: PyObject, p2: PyObject) -> PyResult<PyObject> {
-        let p1 = copy_into_array(p1.extract::<PyBytes>(py)?.data(py));
-        let p2 = copy_into_array(p2.extract::<PyBytes>(py)?.data(py));
+        // TODO: don't panic; raise Python exception instead.
+        let p1 = p1.extract::<PyBytes>(py)?.data(py).try_into().unwrap();
+        let p2 = p2.extract::<PyBytes>(py)?.data(py).try_into().unwrap();
 
         self.inner(py)
             .borrow_mut()
@@ -274,8 +275,9 @@
     ) -> PyResult<PyBytes> {
         let now = Duration::new(now.extract(py)?, 0);
         let parents = DirstateParents {
-            p1: copy_into_array(p1.extract::<PyBytes>(py)?.data(py)),
-            p2: copy_into_array(p2.extract::<PyBytes>(py)?.data(py)),
+            // TODO: don't panic; raise Python exception instead.
+            p1: p1.extract::<PyBytes>(py)?.data(py).try_into().unwrap(),
+            p2: p2.extract::<PyBytes>(py)?.data(py).try_into().unwrap(),
         };
 
         match self.borrow_mut(py)?.pack(parents, now) {