Merge pull request #145 from 863056768/patch-1

还输 > 函数
This commit is contained in:
Sunface 2022-03-06 10:29:29 +08:00 committed by GitHub
commit fe455d79ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -40,7 +40,7 @@ fn main() {
assert_eq!("u32".to_string(), type_of(&x));
}
// 以下还输可以获取传入参数的类型,并返回类型的字符串形式,例如 "i8", "u8", "i32", "u32"
// 以下函数可以获取传入参数的类型,并返回类型的字符串形式,例如 "i8", "u8", "i32", "u32"
fn type_of<T>(_: &T) -> String {
format!("{}", std::any::type_name::<T>())
}
@ -142,6 +142,7 @@ fn main() {
// 整数减法
assert!(1i32 - 2 == __);
assert!(1u8 - 2 == -1);
assert!(3 * 50 == __);
assert!(9.6 / 3.2 == 3.0); // error ! 修改它让代码工作
@ -162,4 +163,4 @@ fn main() {
}
```
> 你可以在[这里](https://github.com/sunface/rust-by-practice)找到答案(在 solutions 路径下)
> 你可以在[这里](https://github.com/sunface/rust-by-practice)找到答案(在 solutions 路径下)