Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust源代码 ch5/src/state/arith_ops.rs pub arith 函数有不懂的地方可否解答? #25

Closed
123zmz123 opened this issue Dec 25, 2020 · 3 comments

Comments

@123zmz123
Copy link

No description provided.

@123zmz123 123zmz123 changed the title rust 代码 ÷ rust源代码 ch5/src/state/arith_ops.rs pub arith 函数有不懂的地方可否解答? Dec 25, 2020
@123zmz123
Copy link
Author

image
请问作者,我知道x y 是pattern variable, 但是为何传入的时候要加*号,个人能力有限找遍了rust文档没有定位到答案,谢谢

@zxh0
Copy link
Owner

zxh0 commented Dec 25, 2020

你好。可以试着去掉*,编译一下,看看编译错误应该就理解了:

$ cargo build
   Compiling ch05 v0.1.0 (luago-book/code/rust/ch05)
error[E0308]: mismatched types
   --> src/state/arith_ops.rs:104:55
    |
104 |                     return Some(LuaValue::Integer(iop(x, y)));
    |                                                       ^
    |                                                       |
    |                                                       expected `i64`, found `&i64`
    |                                                       help: consider dereferencing the borrow: `*x`

error[E0308]: mismatched types
   --> src/state/arith_ops.rs:104:58
    |
104 |                     return Some(LuaValue::Integer(iop(x, y)));
    |                                                          ^
    |                                                          |
    |                                                          expected `i64`, found `&i64`
    |                                                          help: consider dereferencing the borrow: `*y`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
error: could not compile `ch05`

To learn more, run the command again with --verbose.

@123zmz123
Copy link
Author

谢谢提醒😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants