dw2019rust icon indicating copy to clipboard operation
dw2019rust copied to clipboard

How can I trigger swift function from Rust?

Open HakanKumdakci opened this issue 2 years ago • 2 comments

I have one idea about solving. It is creating a bool value in swift and giving its address to Rust. Then setup a timer in swift and check the bool value continuously. When it's time, change value of bool from its address in Rust and it will trigger the function. This scenario could work? How can I solve this problem in efficient way?

Secondly, is there any original type of bitmap in rust? I've seen many crates. Which one do you recommend?

HakanKumdakci avatar Oct 23 '22 13:10 HakanKumdakci

This scenario could work? How can I solve this problem in efficient way?

I don't quite understand the scenario - what does the timer do? I wouldn't recommend having both Swift and Rust accessing the same memory location. Better to pass a bool directly as a normal parameter if you can.

Secondly, is there any original type of bitmap in rust? I've seen many crates. Which one do you recommend?

Not sure, I've looked a few times but never used one in the end.

thombles avatar Oct 25 '22 06:10 thombles

don't quite understand the scenario - what does the timer do? Sorry, with the timer I will check address of boolean in Swift continuously. When the times up I will change the boolean value from its address in Rust and Swift will be know it.

I wouldn't recommend having both Swift and Rust accessing the same memory location. But giving vector address is a common way to use same memory location. Why do you not recommend it? Because of a possibility accessing at the same time because of the timer? Because bool is a primitive value, I've thought it may not be a problem.

HakanKumdakci avatar Oct 25 '22 06:10 HakanKumdakci