[PATCH 1 of 7] rust-dirstate: specify concrete return type of DirsMultiset::iter()

Yuya Nishihara yuya at tcha.org
Sun Sep 8 06:05:41 EDT 2019


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1567911329 -32400
#      Sun Sep 08 11:55:29 2019 +0900
# Node ID 2c5b7c68ea1cc5141d12bd26dd6effe18fe30f44
# Parent  d9ab8eb5616cf509da1ccd3f83aa54ea3b1aa6cc
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.

diff --git a/rust/hg-core/src/dirstate/dirs_multiset.rs b/rust/hg-core/src/dirstate/dirs_multiset.rs
--- a/rust/hg-core/src/dirstate/dirs_multiset.rs
+++ b/rust/hg-core/src/dirstate/dirs_multiset.rs
@@ -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 @@ impl DirsMultiset {
         self.inner.contains_key(key)
     }
 
-    pub fn iter(&self) -> impl Iterator<Item = &Vec<u8>> {
+    pub fn iter(&self) -> DirsMultisetIter {
         self.inner.keys()
     }
 
diff --git a/rust/hg-core/src/lib.rs b/rust/hg-core/src/lib.rs
--- a/rust/hg-core/src/lib.rs
+++ b/rust/hg-core/src/lib.rs
@@ -9,7 +9,7 @@ mod dirstate;
 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,


More information about the Mercurial-devel mailing list