rust/hg-cpython/src/dirstate/dirs_multiset.rs
changeset 44233 281642cd1d04
parent 44203 2a24ead003f0
child 44234 bad4e7b361d2
equal deleted inserted replaced
44232:06df075b8925 44233:281642cd1d04
    23     DirsMultiset, DirsMultisetIter, DirstateMapError, DirstateParseError,
    23     DirsMultiset, DirsMultisetIter, DirstateMapError, DirstateParseError,
    24     EntryState,
    24     EntryState,
    25 };
    25 };
    26 
    26 
    27 py_class!(pub class Dirs |py| {
    27 py_class!(pub class Dirs |py| {
    28     data inner: PySharedRefCell<DirsMultiset>;
    28     data inner_: PySharedRefCell<DirsMultiset>;
    29 
    29 
    30     // `map` is either a `dict` or a flat iterator (usually a `set`, sometimes
    30     // `map` is either a `dict` or a flat iterator (usually a `set`, sometimes
    31     // a `list`)
    31     // a `list`)
    32     def __new__(
    32     def __new__(
    33         _cls,
    33         _cls,
    70             PySharedRefCell::new(inner),
    70             PySharedRefCell::new(inner),
    71         )
    71         )
    72     }
    72     }
    73 
    73 
    74     def addpath(&self, path: PyObject) -> PyResult<PyObject> {
    74     def addpath(&self, path: PyObject) -> PyResult<PyObject> {
    75         self.inner_shared(py).borrow_mut().add_path(
    75         self.inner(py).borrow_mut().add_path(
    76             HgPath::new(path.extract::<PyBytes>(py)?.data(py)),
    76             HgPath::new(path.extract::<PyBytes>(py)?.data(py)),
    77         ).and(Ok(py.None())).or_else(|e| {
    77         ).and(Ok(py.None())).or_else(|e| {
    78             match e {
    78             match e {
    79                 DirstateMapError::EmptyPath => {
    79                 DirstateMapError::EmptyPath => {
    80                     Ok(py.None())
    80                     Ok(py.None())
    88             }
    88             }
    89         })
    89         })
    90     }
    90     }
    91 
    91 
    92     def delpath(&self, path: PyObject) -> PyResult<PyObject> {
    92     def delpath(&self, path: PyObject) -> PyResult<PyObject> {
    93         self.inner_shared(py).borrow_mut().delete_path(
    93         self.inner(py).borrow_mut().delete_path(
    94             HgPath::new(path.extract::<PyBytes>(py)?.data(py)),
    94             HgPath::new(path.extract::<PyBytes>(py)?.data(py)),
    95         )
    95         )
    96             .and(Ok(py.None()))
    96             .and(Ok(py.None()))
    97             .or_else(|e| {
    97             .or_else(|e| {
    98                 match e {
    98                 match e {
   107                     }
   107                     }
   108                 }
   108                 }
   109             })
   109             })
   110     }
   110     }
   111     def __iter__(&self) -> PyResult<DirsMultisetKeysIterator> {
   111     def __iter__(&self) -> PyResult<DirsMultisetKeysIterator> {
   112         let leaked_ref = self.inner_shared(py).leak_immutable();
   112         let leaked_ref = self.inner(py).leak_immutable();
   113         DirsMultisetKeysIterator::from_inner(
   113         DirsMultisetKeysIterator::from_inner(
   114             py,
   114             py,
   115             unsafe { leaked_ref.map(py, |o| o.iter()) },
   115             unsafe { leaked_ref.map(py, |o| o.iter()) },
   116         )
   116         )
   117     }
   117     }
   118 
   118 
   119     def __contains__(&self, item: PyObject) -> PyResult<bool> {
   119     def __contains__(&self, item: PyObject) -> PyResult<bool> {
   120         Ok(self.inner_shared(py).borrow().contains(HgPath::new(
   120         Ok(self.inner(py).borrow().contains(HgPath::new(
   121             item.extract::<PyBytes>(py)?.data(py).as_ref(),
   121             item.extract::<PyBytes>(py)?.data(py).as_ref(),
   122         )))
   122         )))
   123     }
   123     }
   124 });
   124 });
   125 
   125 
   126 py_shared_ref!(Dirs, DirsMultiset, inner, inner_shared);
   126 py_shared_ref!(Dirs, DirsMultiset, inner_, inner);
   127 
   127 
   128 impl Dirs {
   128 impl Dirs {
   129     pub fn from_inner(py: Python, d: DirsMultiset) -> PyResult<Self> {
   129     pub fn from_inner(py: Python, d: DirsMultiset) -> PyResult<Self> {
   130         Self::create_instance(py, PySharedRefCell::new(d))
   130         Self::create_instance(py, PySharedRefCell::new(d))
   131     }
   131     }