Module 1Getting StartedLesson 3 of 1015 min
Comments, Style & Cargo Mindset
How Rust projects are organized locally, what the playground can/can’t do, and how to write readable quant code.
Comments
rust
// line comment
/// Doc comment — for public APIs (shows in rustdoc)
fn mid(bid: f64, ask: f64) -> f64 {
(bid + ask) / 2.0 // trailing comment
}Local vs playground
| Playground (this site) | Local cargo |
|
|---|---|---|
| Crates | almost none | crates.io |
| Binary | single snippet | project with modules |
| Tests | limited | cargo test |
| Release opts | constrained | --release for benches |
Mental model for local projects:
my-pricer/
Cargo.toml # dependencies
src/main.rs # binary entry
src/lib.rs # library root (optional)
src/bs.rs # moduleYou don’t need Cargo to learn here — but knowing it exists means you won’t be surprised later when we talk about serde and rayon.
Style that scales
- Prefer clarity over clever one-liners in pricing code
- Name variables after domain terms:
spot,strike,time_to_expiry,rate - Keep functions small; pure math functions are easy to test
Exercise
Rewrite noisy names into clear domain names and document a tiny helper.
Challenge
Add spread(bid, ask) with a doc comment and print mid + spread for two symbols.
Tips
- /// doc comments go directly above the item
- Domain names beat x/y/z in finance code
- Playground is for learning; Cargo is for real systems
Try it live
Comments, Style & Cargo MindsetRust 2021
Loading editor…
Output
Press Run to compile and execute.