You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
structPoundOfForce(f64);structNewtons(f64);fncompute_thruster_force() -> PoundOfForce{todo!("Ask a rocket scientist at NASA")}fnset_thruster_force(force:Newtons){// ...}fnmain(){let force = compute_thruster_force();set_thruster_force(force);}
compile with cargo run shows:
❯ cargo run
Compiling exercise v0.1.0 (/Users/z/code/exercise)
error[E0308]: mismatched types
--> src/main.rs:14:24
|
14 | set_thruster_force(force);| ------------------ ^^^^^ expected struct `Newtons`, found struct `PoundOfForce`||| arguments to this functionare incorrect
|
note: functiondefined here
--> src/main.rs:8:4
|
8 | fn set_thruster_force(force: Newtons) {
| ^^^^^^^^^^^^^^^^^^ --------------
For more information about this error, try `rustc --explain E0308`.
error: could not compile `exercise` due to previous error
So this maybe a typo in the code?
The text was updated successfully, but these errors were encountered:
Thanks for opening the issue! The compilation error is actually intentional: it shows you that Rust found the error in the use of units at compilation time — in the real world, the mistake was found when the Mars Climate Orbiter crashed into Mars.
I'm working on adding support for speaker notes #53 and then I'll fill in such details on all the pages.
https://google.github.io/comprehensive-rust/structs/tuple-structs.html
compile with
cargo run
shows:So this maybe a typo in the code?
The text was updated successfully, but these errors were encountered: