istio / ztunnel

The `ztunnel` component of ambient mesh
Apache License 2.0
296 stars 100 forks source link

Development tips: getting started developing in rust on ztunnel #153

Open howardjohn opened 1 year ago

howardjohn commented 1 year ago

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:

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

ericvn commented 1 year ago

Thanks.

nmittler commented 1 year ago

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

kfaseela commented 1 year ago

Thanks @howardjohn

hzxuzhonghu commented 11 months ago

no stale