Skip to content

Rust

Insert Code to Leetcode Generated Code

When I wrote leetcode in vscode with the plugin, I named generated leetcode file with format as[0-9]+(e.g, as123.rs) and put them under src. However, I have encountered some painpoints:

  1. The generated file isn't used by main.rs so the rust analyzer will ignore it, so I need to add mod as123; in main.rs every time.
  2. The generated code doesn't contain struct Soltuion definition so I need to add it every time.
  3. When I want to debug locally, I need to write the test function from scratch. It doesn't cost much but it's verbose.

These painpoints are trivial, but they're quite verbose. By using build script build.rs, I'm succeeded solving my painpoints!

Make Bazel Work in MacOS for Iceoryx2

In iceoryx2, it uses bazel to build C/C++ bindings. Hence, they want to use bazel for rust for a better unification in iceoryx2.

Currently foreign_cc is used to build the C binding and cc_library to build the C++ bindings. In order to fully exhaust the capabilities of bazel, the C binding and therefore the Rust code should be build with rules_rust.

When I tried it, I found it doesn't work in my MacOS. This blog records some knowledge when I learned bazel and how I solved the problem. It doesn't talk about why we use bazel in a rust project.

Iceoryx2 Lockfree Structures Benchmark

This page lists the benchmark results of the iceoryx2 lockfree structures. At the beginning, I hold the assumption that the lockfree structures are faster. However, that's not a true assumption. There is no significant differences between locked implementation and lockfree implementation in my test cases.

You can view my benchmark code here.

Rust Async Brief

As I tried to write a demo by rust wasm, I was thinking about what should be a better signature to export by rust for wasm. In the demo, I exported the process function as a promise:

pub async fn process(input: &[u8]) -> js_sys::Promise

This blog discusses my understanding of async concept in rust and discussion whether returning a promise is a good choice.