Brendonovich / swift-rs

Call Swift functions from Rust with ease!
Apache License 2.0
246 stars 28 forks source link

Enable creating SRArray from rust and passing to Swift as arg #59

Open tleyden opened 5 months ago

tleyden commented 5 months ago

Is it possible to create an SRArray<SRData> on the rust side and pass it as a parameter to a swift function? Do you have any examples of doing this?

Basically what I'm trying to do is capture a series of screenshots, convert them from CGImage -> SRData, and then pass an array of SRData to a swift function. It can't all be on the swift side though, the rust code needs to collect the array of SRData and then pass it back to the swift side as an array.

rust calls swift to get an `SRData`
rust calls swift to get an `SRData`
..
rust collects `SRData` objects into an SRArray<SRData>  <-- this is the part that is missing 
rust calls swift and passes SRArray<SRData>

Does this sound like the right approach, or would SRObjectArray<CGImage> or defining a custom object be easier?

tleyden commented 5 months ago

It seems like this might not be possible yet. From the docs:

Currently, the only types that can be created from Rust are number types, boolean, SRString, and SRData

Brendonovich commented 5 months ago

Yea SRArray can't be created from rust yet, should be possible but haven't implemented it yet

tleyden commented 5 months ago

@Brendonovich ok thanks for the clarification. I'll change the ticket title to reflect that