Recently, I read an introduction to a Shard called Tartrazine for syntax highlighting, and I thought it was exactly what I needed. But I realized that writing all the logic in Crystal could be a lot of work to maintain. To make things easier, I decided, with the help of ChatGPT, to create a C wrapper for the Rust tool bat and link it to Crystal. I set up two repositories to try out this idea, and it worked.
require "wombat"
puts Wombat.pretty_string(%{puts "hello world"})
However, I found that adding and maintaining a C wrapper for a Rust library takes a lot of time. If you think of the Rust library as a big department store, the C wrapper should be kept small, like a vending machine with just a few buttons. Press one, and you get the most important items from the store.
Even so, I believe that if I want to keep using Crystal in the long run, it’s important to be able to take the necessary functions from Rust, create C-compatible libraries, and link them to Crystal.
I tried creating a C wrapper for Syntect as well, and while I had some success, I found it quite challenging with my current skills.