Skip to content

Commit

Permalink
Implement IntoPy<PyObject> for &PathBuf
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Jul 4, 2021
1 parent 4b88dd1 commit 11d7d66
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ PyO3 versions, please see the [migration guide](https://pyo3.rs/main/migration.h
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Implement `IntoPy<PyObject>` for `&PathBuf`. [#1721](https://github.com/PyO3/pyo3/pull/1712)

## [0.14.0] - 2021-07-03

### Packaging
Expand Down
8 changes: 7 additions & 1 deletion src/conversions/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ impl IntoPy<PyObject> for PathBuf {
}
}

impl<'a> IntoPy<PyObject> for &'a PathBuf {
fn into_py(self, py: Python) -> PyObject {
self.as_os_str().to_object(py)
}
}

#[cfg(test)]
mod test {
use crate::{types::PyString, IntoPy, PyObject, Python, ToPyObject};
Expand Down Expand Up @@ -120,7 +126,7 @@ mod test {
let pystring: &PyString = pyobject.extract(py).unwrap();
assert_eq!(pystring.to_string_lossy(), obj.as_ref().to_string_lossy());
let roundtripped_obj: PathBuf = pystring.extract().unwrap();
assert!(obj.as_ref() == roundtripped_obj.as_path());
assert_eq!(obj.as_ref(), roundtripped_obj.as_path());
}
let path = Path::new("Hello\0\n🐍");
test_roundtrip::<&Path>(py, path);
Expand Down

0 comments on commit 11d7d66

Please sign in to comment.