News for hackers. Stuff that matters.
Re:Chris Lattner left Swift core team by maxthegeek1 on Monday February 21, 2022 @09:15PM (#30423325)
Does async rust prevent the use of C FFI? A quick google shows me nothing there.
Re:Chris Lattner left Swift core team by boardwaalk on Monday February 21, 2022 @09:55PM (#30423548)
It doesn't. You can call non-async Rust and C from async Rust just fine. You just have to be beware of calling blocking things if you're not in a context where blocking is ok (i.e. in a CPU work pool thread).

I'm not sure what the GP meant, to be honest. Async "colored" code does have an tendency to "infect" more and more of your codebase, but you can still write and integrate big chunks of non-async code (e.g. a parser or a network protocol) if you're mindful about your design.

Re:Chris Lattner left Swift core team by ithkuil on Tuesday February 22, 2022 @02:37AM (#30425040)
Sure, you can technically call other rust code from async rust and thus you can also technically call C code via FFI, but if that code blocks you have a problem. There are ways around it but they are hard to use and create the pressure towards just rewriting the whole thing in rust.

I could be wrong though. The reason I like to discuss these things here is the opportunity to be proven wrong by someone who knows more and offers a counter-example

Re:Chris Lattner left Swift core team by maxthegeek1 on Wednesday February 23, 2022 @11:58AM (#30443212)
If you need to call blocking code from an async code just use spawn_blocking.

https://docs.rs/tokio/latest/tokio/task/fn.spawn_blocking.ht...

Re:Chris Lattner left Swift core team by ithkuil on Wednesday February 23, 2022 @12:24PM (#30443611)
Yes you can. And this will create threads on demand as needed.

But you need to know when you must call this and when it's ok to not call it.

The type system won't help you with that. But if you forget to call it you can cause starvation and if you call it too often you may create too many threads.

What I see in the ecosystem is that such tricks are perceived as hacks and that it would be just better if one could just write a pure rust reimpl.

Surely there are enough reasons that drive people to reimplements stuff in rust. I think this aspect of async nudges people even further into that though.