Skip to content
Snippets Groups Projects
Commit 09eb477eec65 authored by Georges Racinet's avatar Georges Racinet :squid:
Browse files

rust-pyo3-path: more conversions to Python

The `PyHgPathDirstateV2Result` new type is unfortunately heavily
named, but it should allow for very straightforward conversions
of collections.
parent c5773445d350
No related branches found
No related tags found
2 merge requests!1292Draft: 7.0rc preparation,!1233rust-pyo3: dirstate bindings
......@@ -13,5 +13,6 @@
use std::convert::Infallible;
use hg::dirstate::on_disk::DirstateV2ParseError;
use hg::utils::hg_path::{HgPath, HgPathBuf};
......@@ -16,5 +17,7 @@
use hg::utils::hg_path::{HgPath, HgPathBuf};
use crate::exceptions::dirstate_v2_error;
#[derive(Eq, Ord, PartialEq, PartialOrd, Hash, derive_more::From)]
pub struct PyHgPathRef<'a>(pub &'a HgPath);
......@@ -31,6 +34,45 @@
}
}
#[derive(Eq, Ord, PartialEq, PartialOrd, Hash, derive_more::From)]
pub struct PyHgPathBuf(pub HgPathBuf);
// This is for now equivalent to taking a ref as `HgPath` and using
// `HgPathRef`. One day, perhaps, this variant for owned data could be
// implemented without allocation.
impl<'py> IntoPyObject<'py> for PyHgPathBuf {
type Target = PyBytes;
type Output = Bound<'py, Self::Target>;
type Error = Infallible;
fn into_pyobject(
self,
py: Python<'py>,
) -> Result<Self::Output, Self::Error> {
Ok(PyBytes::new(py, self.0.as_bytes()))
}
}
pub struct PyHgPathDirstateV2Result<'a>(
pub Result<&'a HgPath, DirstateV2ParseError>,
);
impl<'py> IntoPyObject<'py> for PyHgPathDirstateV2Result<'_> {
type Target = PyBytes;
type Output = Bound<'py, Self::Target>;
type Error = PyErr;
fn into_pyobject(
self,
py: Python<'py>,
) -> Result<Self::Output, Self::Error> {
Ok(PyBytes::new(
py,
self.0.map_err(dirstate_v2_error)?.as_bytes(),
))
}
}
#[allow(dead_code)]
pub fn paths_py_list<I, U>(
py: Python<'_>,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment