diff rust/hg-direct-ffi/src/ancestors.rs @ 40933:18513d6ef7d4

rust: changed Graph.parents to return [Revision; 2] This will allow for simple iteration on parent revisions, such as: for parent in graph.parents(rev)?.iter().cloned() This seems to be a zero overhead abstraction once built in release mode. Differential Revision: https://phab.mercurial-scm.org/D5415
author Georges Racinet <gracinet@anybox.fr>
date Fri, 30 Nov 2018 00:44:04 +0100
parents 443eb4bc41af
children 6a551a2dc666
line wrap: on
line diff
--- a/rust/hg-direct-ffi/src/ancestors.rs	Tue Dec 11 17:31:54 2018 +0100
+++ b/rust/hg-direct-ffi/src/ancestors.rs	Fri Nov 30 00:44:04 2018 +0100
@@ -44,12 +44,12 @@
 
 impl Graph for Index {
     /// wrap a call to the C extern parents function
-    fn parents(&self, rev: Revision) -> Result<(Revision, Revision), GraphError> {
+    fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> {
         let mut res: [c_int; 2] = [0; 2];
         let code =
             unsafe { HgRevlogIndex_GetParents(self.index, rev, &mut res as *mut [c_int; 2]) };
         match code {
-            0 => Ok((res[0], res[1])),
+            0 => Ok(res),
             _ => Err(GraphError::ParentOutOfRange(rev)),
         }
     }
@@ -176,10 +176,10 @@
     struct Stub;
 
     impl Graph for Stub {
-        fn parents(&self, r: Revision) -> Result<(Revision, Revision), GraphError> {
+        fn parents(&self, r: Revision) -> Result<[Revision; 2], GraphError> {
             match r {
                 25 => Err(GraphError::ParentOutOfRange(25)),
-                _ => Ok((1, 2)),
+                _ => Ok([1, 2]),
             }
         }
     }