Hey, for our FFI port, I want to implement the tra...
# development
h
Hey, for our FFI port, I want to implement the trait FromPyObject on the PathGlobs struct defined in Rust. It would allow our FFI functions to request that type in function signature and do the right thing, rather than having to request a &PyAny But the struct is defined in a different crate, so rust doesn't allow adding a trait Instead, the two options seem to be: 1) create a light weight wrapper struct. Implement Deref on it so it's accessed the same, right? 2) use a free function rather than the trait. This is what we currently do. Thoughts on which is preferable?
w
1) would be the most idiomatic probably.
rather than
Deref
though, maybe implement
From
? i don’t think we want to have the conversion type used anywhere other than at the API boundary
👍 1
with
impl From<PyPathGlobs> for PathGlobs
, you’d accept
py_path_globs: PyPathGlobs
in your interface, and then call
py_path_globs.into()
to convert to
PathGlobs
at a callsite
👍 1
h
Cool, thanks!
w
but, also… another possibility would be to make
PyPathGlobs
a true python class, with a single field for a native
PathGlobs
👍 1
similar to
PyDigest
that would avoid creating a Python object on one side and then converting it into a Rust object on the other.
h
I thought about that. That would mean eventually porting all our intrinsic FS types to do that, right? I'm doing this PathGlobs port as an example for how to do the rest
w
it doesn’t need to. can do it for performance, but if it also leads to cleaner FFI code, that’s nice too. only downside i see is that our API doc generation will need to be native-code aware.
👍 1