`Cow` equivalent in PyO3
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.2k
- Forks
- 1k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 66
Description
I propose to add a type to support copy-on-write behavior just like the std::borrow::Cow. The Cow type in std is usually unwanted because a reference to a Python object is held though PyRef. Therefore something like the following will be useful:
enum PyCow<'a, B>
where
B: 'a + ToOwned + PyClass,
{
Borrowed(PyRef<'a, B>),
Owned(<B as ToOwned>::Owned),
}
This is useful when a function accepts both a Python object or something that can be converted to the object. For example, if I have a rust-implemented Python-type Decimal, a function that accepts a either Decimal or a string can take this as input to prevent a copy.
(Not sure if this is useful for other people, or if it's compatible with the new Bound API or not... Just post the idea here for discussion)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue proposes a PyCow type for copy-on-write handling of Python objects, using PyRef and considering compatibility with the Bound API. Start by reviewing those APIs and std::borrow::Cow; done would require a resolved design and maintainer agreement on whether and how this belongs in PyO3.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100