Open cmpute opened 7 months ago
I think there is definitely space for this kind of idea, and it is strongly related to what we just added in #3802 . There's a lot of unresolved questions in my head about this, though.
B: PyClass
or B: PyTypeInfo
?PyRef
or Bound
for the python variant?&B
variant to become a complete superset of normal Cow
?Folks willing to explore this idea further are very welcome, whether it gets merged immediately into pyo3 or we allow time for this idea to mature as a separate crate, I can see potential in it.
I propose to add a type to support copy-on-write behavior just like the
std::borrow::Cow
. TheCow
type instd
is usually unwanted because a reference to a Python object is held thoughPyRef
. Therefore something like the following will be useful: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 eitherDecimal
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)