hundreds-breakfast-49010
09/11/2020, 7:12 PMexterns
functions designed to work with `Value`s and `Failure`s, which wrap `PyObject`s, when a lot of the time what we want to do with the result of those functions is get the underlying PyObject
and do something to it with the cpython apihundreds-breakfast-49010
09/11/2020, 7:13 PMPyObjects
fairly straightforwardly, so I think it might be possible to fairly easily convert our externs
functions to ones dealing directly in cpython types, and then call the appropriate conversion methods at call sites if and when we need `Value`shundreds-breakfast-49010
09/11/2020, 7:14 PMwitty-crayon-22786
09/11/2020, 8:03 PMAsRef<PyObject>
, which would let you call with either a PyObject
or a Value
witty-crayon-22786
09/11/2020, 8:46 PMValue
to PyObject
might involve acquiring the gil and cloning, but viewing a Value
as a `&PyObject`is very cheap.hundreds-breakfast-49010
09/11/2020, 8:50 PMAsRef<PyObject>
seems like the right choice of type for our APIs around this to acceptwitty-crayon-22786
09/11/2020, 9:07 PMAsRef
and Deref
⦠one of those.)hundreds-breakfast-49010
09/11/2020, 9:10 PMAsRef
,but yeah whichever one makes the typechecker happywitty-crayon-22786
09/11/2020, 9:13 PMAlternative answer: you can Deref to only one other type, but you can AsRef to many. So if you have a MyType(String, i32), you could e g implement AsRef for both &String and &i32, but with Deref you'd have to choose one of them.
hundreds-father-404
09/12/2020, 7:19 PMhundreds-breakfast-49010
09/12/2020, 8:15 PMhundreds-breakfast-49010
09/12/2020, 8:37 PM