ztunnel icon indicating copy to clipboard operation
ztunnel copied to clipboard

Development tips: getting started developing in rust on ztunnel

Open howardjohn opened this issue 2 years ago • 4 comments

Since most developers on the project are new to rust, I thought it would be useful to have an issue to discuss tips for onboarding. Feel free to edit or comment.

IDEs

Intellij (or related IDEs) have a rust plugin that is pretty solid, with some tweaks:

  • Follow https://www.reddit.com/r/rust/comments/sqy10t/guide_getting_the_most_out_of_intellij/ for best use. You really should do the "Enable experimental features" part or most things won't work.
  • Set rustfmt as the formatter: https://plugins.jetbrains.com/plugin/8182-rust/docs/#reformat.
  • Check everything under Editor > General > Auto Import.

VSCode or other LSP editors with rust-analyze is also great.

Note: due to the complexity of the language, the experience of both of these is still worse than Go unfortunately

Useful commands

cargo build # build in debug mode
cargo build --release # build in release mode - takes a while, but gives an optimized build. Do not benchmark without --release!!!
cargo check [--tests] # quickly check for compile errors
cargo clippy --fix --allow-staged --allow-dirty # find and fix (sometimes) lint errors
cargo fmt # format things

Resources

https://doc.rust-lang.org/book/ - the canonical learning rust book.

https://www.zero2prod.com/ - good real world walkthrough

https://tokio.rs/tokio/tutorial - good intro to async and tokio (library we use)

Coding style

Rust allows a wide variety of coding styles. Because most developers on the project are new-er to Rust, avoid use of complex Rust features when possible. If a function doesn't need to be generic, do not make it so. If a we can save 10nanoseconds on a infrequent codepath by using complex lifetimes - opt for a clone() instead.

Running locally

See https://github.com/istio/ztunnel/blob/master/LOCAL.md

Useful tools

https://nexte.st/ - Better test runner

howardjohn avatar Nov 17 '22 21:11 howardjohn

Thanks.

ericvn avatar Nov 18 '22 16:11 ericvn

@howardjohn mind adding a link to the Rust async programming book? https://rust-lang.github.io/async-book/

nmittler avatar Dec 02 '22 20:12 nmittler

Thanks @howardjohn

kfaseela avatar Dec 04 '22 06:12 kfaseela

no stale

hzxuzhonghu avatar Dec 08 '23 01:12 hzxuzhonghu