##// END OF EJS Templates
rust-dirstate: improve API of `DirsMultiset`...
Raphaël Gomès -
r42995:849e744b default
parent child Browse files
Show More
@@ -12,7 +12,7 b' use crate::{'
12 12 dirstate::EntryState, utils::files, DirsIterable, DirstateEntry,
13 13 DirstateMapError,
14 14 };
15 use std::collections::hash_map::{Entry, Iter};
15 use std::collections::hash_map::Entry;
16 16 use std::collections::HashMap;
17 17
18 18 #[derive(PartialEq, Debug)]
@@ -98,12 +98,12 b' impl DirsMultiset {'
98 98 Ok(())
99 99 }
100 100
101 pub fn contains_key(&self, key: &[u8]) -> bool {
101 pub fn contains(&self, key: &[u8]) -> bool {
102 102 self.inner.contains_key(key)
103 103 }
104 104
105 pub fn iter(&self) -> Iter<Vec<u8>, u32> {
106 self.inner.iter()
105 pub fn iter(&self) -> impl Iterator<Item = &Vec<u8>> {
106 self.inner.keys()
107 107 }
108 108
109 109 pub fn len(&self) -> usize {
@@ -12,7 +12,7 b' use std::cell::RefCell;'
12 12
13 13 use cpython::{
14 14 exc, ObjectProtocol, PyBytes, PyDict, PyErr, PyObject, PyResult,
15 ToPyObject,
15 PythonObject, ToPyObject,
16 16 };
17 17
18 18 use crate::dirstate::extract_dirstate;
@@ -93,26 +93,21 b' py_class!(pub class Dirs |py| {'
93 93 // of having it work to continue working on the rest of the module
94 94 // hopefully bypassing Python entirely pretty soon.
95 95 def __iter__(&self) -> PyResult<PyObject> {
96 let dict = PyDict::new(py);
97
98 for (key, value) in self.dirs_map(py).borrow().iter() {
99 dict.set_item(
100 py,
101 PyBytes::new(py, &key[..]),
102 value.to_py_object(py),
103 )?;
104 }
105
106 let locals = PyDict::new(py);
107 locals.set_item(py, "obj", dict)?;
108
109 py.eval("iter(obj)", None, Some(&locals))
96 let dirs = self.dirs_map(py).borrow();
97 let dirs: Vec<_> = dirs
98 .iter()
99 .map(|d| PyBytes::new(py, d))
100 .collect();
101 dirs.to_py_object(py)
102 .into_object()
103 .iter(py)
104 .map(|o| o.into_object())
110 105 }
111 106
112 107 def __contains__(&self, item: PyObject) -> PyResult<bool> {
113 108 Ok(self
114 109 .dirs_map(py)
115 110 .borrow()
116 .contains_key(item.extract::<PyBytes>(py)?.data(py).as_ref()))
111 .contains(item.extract::<PyBytes>(py)?.data(py).as_ref()))
117 112 }
118 113 });
General Comments 0
You need to be logged in to leave comments. Login now