rust-pyo3: helper to return sets of revisions
authorGeorges Racinet <georges.racinet@cloudcrane.io>
Tue, 24 Dec 2024 14:34:23 +0100
changeset 52807 0fc15732fe7b
parent 52806 0a0ed46ef6d6
child 52808 6222326bd13e
rust-pyo3: helper to return sets of revisions This will be less used than `revs_py_list`, but is better to separate here for readability of the caller (candidate in `InnerRevlog` to be implemented right afterwards).
rust/hg-pyo3/src/revision.rs
--- a/rust/hg-pyo3/src/revision.rs	Tue Dec 24 01:29:07 2024 +0100
+++ b/rust/hg-pyo3/src/revision.rs	Tue Dec 24 14:34:23 2024 +0100
@@ -1,5 +1,5 @@
 use pyo3::prelude::*;
-use pyo3::types::PyList;
+use pyo3::types::{PyList, PySet};
 
 use hg::revlog::RevlogIndex;
 use hg::{BaseRevision, Revision, UncheckedRevision};
@@ -116,3 +116,14 @@
 {
     Ok(PyList::new(py, revs.into_iter().map(PyRevision::from))?.unbind())
 }
+
+#[allow(dead_code)]
+pub fn revs_py_set<U>(
+    py: Python<'_>,
+    revs: impl IntoIterator<Item = Revision, IntoIter = U>,
+) -> PyResult<Py<PySet>>
+where
+    U: ExactSizeIterator<Item = Revision>,
+{
+    Ok(PySet::new(py, revs.into_iter().map(PyRevision::from))?.unbind())
+}