I hope it is not overly complicated to use Rust as the article suggests

It seems to be genuinely a case where Zig fits better the task/approach that the post author wanted.

I think the Rust version could have been designed better. The problem in this article came from trying to use #ifdef-like approach of putting multiple different implementations in the same functions, with heavy use of #[cfg]. That's not a nice approach, especially when working with strictly-typed libraries.

Rust version could have been more elegant if it used traits like ReadKeys that could be implemented for each type of hardware independently, without lots of #[cfg].

It also seems that Zig's libraries for different keyboards happen to have same API/types, and Rust equivalents had different APIs/types. So in Zig the libraries have already abstracted away (or never handled) the hardware differences that the Rust version had to deal with.

4 Likes