Hacker News new | ask | show | jobs
by outside1234 1380 days ago
My first piece of advice is to just start writing code.

If you are not specifically interested in super high performance systems level code, my second piece of advice would be to write code that avoids lifetime annotations until you get the basics of the borrow checker down.

For me, this meant writing a gRPC API with Rust using `tonic` with a `diesel` based persistence backend and observability with `tracing` and `opentelemetry`. This gives you a good survey of the basics and you'll learn about all of the core traits and language features in the process.

2 comments

Just start coding while avoiding lifetimes is great advice, but that's easier said than done. Rust makes some hard things simple and exposes hidden complexity in things you thought were simple.

Maybe I'd reframe it as "just start writing code, and use RC<> liberally to avoid lifetimes until you get a handle on them."

Also avoid async for that first project too.

Yes - that's also good advice (using Arc/RC to liberally avoid ownership issues). I've personally had good experiences with async, but I can also see how that could be challenging depending on the background you are coming from.
This is what I did. Still haven't figured out lifetimes or async, but I was impressed with how easily I managed to write something that works[1]...

[1] https://github.com/jcuenod/clickhouse-set-cover

Slightly off topic question/comment: You are running an async server, together with a blocking database client? That sounds more like a very tricky place ot get started. Are you dispatching all your database queries into an extra threadpool?
Yes, as you have expected tokio has spawn_blocking which allows you to throw misbehaving code into a thread pool.

This started to disgust me so I jumped to sqlx.

Yes - what throwaway said. Good suggestion as well to use sqlx instead.