changeset 42885:a03a29462c0a

rust-dirstate: specify concrete return type of DirsMultiset::iter() This allows us to put a returned iterator in a struct. We could implement DirsMultisetIter(hash_map::Keys<..>) struct to hide the implementation detail, but I think type alias is good enough for us.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 08 Sep 2019 11:55:29 +0900
parents 775224e26d74
children 7083ac37314f
files rust/hg-core/src/dirstate/dirs_multiset.rs rust/hg-core/src/lib.rs
diffstat 2 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate/dirs_multiset.rs	Sat Apr 27 02:04:05 2019 +0200
+++ b/rust/hg-core/src/dirstate/dirs_multiset.rs	Sun Sep 08 11:55:29 2019 +0900
@@ -11,9 +11,12 @@
 use crate::{
     dirstate::EntryState, utils::files, DirstateEntry, DirstateMapError,
 };
-use std::collections::hash_map::Entry;
+use std::collections::hash_map::{self, Entry};
 use std::collections::HashMap;
 
+// could be encapsulated if we care API stability more seriously
+pub type DirsMultisetIter<'a> = hash_map::Keys<'a, Vec<u8>, u32>;
+
 #[derive(PartialEq, Debug)]
 pub struct DirsMultiset {
     inner: HashMap<Vec<u8>, u32>,
@@ -105,7 +108,7 @@
         self.inner.contains_key(key)
     }
 
-    pub fn iter(&self) -> impl Iterator<Item = &Vec<u8>> {
+    pub fn iter(&self) -> DirsMultisetIter {
         self.inner.keys()
     }
 
--- a/rust/hg-core/src/lib.rs	Sat Apr 27 02:04:05 2019 +0200
+++ b/rust/hg-core/src/lib.rs	Sun Sep 08 11:55:29 2019 +0900
@@ -9,7 +9,7 @@
 pub mod discovery;
 pub mod testing; // unconditionally built, for use from integration tests
 pub use dirstate::{
-    dirs_multiset::DirsMultiset,
+    dirs_multiset::{DirsMultiset, DirsMultisetIter},
     dirstate_map::DirstateMap,
     parsers::{pack_dirstate, parse_dirstate, PARENT_SIZE},
     CopyMap, DirstateEntry, DirstateParents, EntryState, StateMap,