4 回答

TA貢獻(xiàn)1845條經(jīng)驗(yàn) 獲得超8個(gè)贊
let () = x;
error[E0308]: mismatched types --> <anon>:2:29 | 2 | let mut my_number: () = 32.90; | ^^^^^ expected (), found floating-point variable | = note: expected type `()` = note: found type `{float}` error: aborting due to previous error
error: no method named `what_is_this` found for type `{float}` in the current scope --> <anon>:3:15 | 3 | my_number.what_is_this(); | ^^^^^^^^^^^^ error: aborting due to previous error
error: attempted access of field `what_is_this` on type `{float}`, but no field with that name was found --> <anon>:3:5 | 3 | my_number.what_is_this | ^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error
{float}
f32
f64
{float}
f64
i32
.)
f32
f64
32.90.eq(&32.90)
f64

TA貢獻(xiàn)2012條經(jīng)驗(yàn) 獲得超12個(gè)贊
std::intrinsics::type_name
#![feature(core_intrinsics)]fn print_type_of<T>(_: &T) { println!("{}", unsafe { std::intrinsics::type_name::<T>() });}fn main() { print_type_of(&32.90); // prints "f64" print_type_of(&vec![1, 2, 4]); // prints "std::vec::Vec<i32>" print_type_of(&"foo"); // prints "&str"}

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超2個(gè)贊
UPD
std::intrinsics::get_tydesc<T>()
fn print_type_of<T>(_: &T) -> () { let type_name = unsafe { (*std::intrinsics::get_tydesc::<T>()).name }; println!("{}", type_name);}fn main() -> () { let mut my_number = 32.90; print_type_of(&my_number); // prints "f64" print_type_of(&(vec!(1, 2, 4))); // prints "collections::vec::Vec<int>"}
{:?}
添加回答
舉報(bào)