Rs
Module 2Slices & ViewsLesson 9 of 925 min

Module 2 Lab: Quote Toolkit

Combine ownership ideas into a small quote helper library.

Build a mini toolkit

  1. struct Quote { bid, ask }
  2. mid, spread via &Quote
  3. fn improve(&mut self-ish function)
  4. fn label(q: &Quote, sym: &str) -> String

No heap sharing tricks — just clean borrows.

Work until all prints look right; then try the challenge.

Challenge

Track a Vec of mid history by pushing mid after each successful improve.

Tips
  • Return bool or Result for rejected improves
  • Keep mutation functions small
  • You're ready for structs/enums in Module 3

Try it live

Module 2 Lab: Quote ToolkitRust 2021
Loading editor…
Output
Press Run to compile and execute.