-
rust에서 타입type_of을 알아보는 방법ex:String의 타입 알아보기코딩Coding/★Rust★기초★Syntax 2022. 4. 20. 06:36728x90
~/Documents/Project/Github/rust_project/training_rustacean_rust/src/main.rs.html 1 use std::any::type_name; 2 3 fn type_of<T>(_: T) -> &'static str { 4 type_name::<T>() 5 } 6 7 fn main() { 8 let my_name = "Billybrobby"; 9 let my_country = "USA"; 10 let my_home = "Korea"; 11 12 println!("{}", type_of(my_name)); 13 let together = format!( 14 "I am {} and I come from {} but I live in {}.", 15 my_name, my_country, my_home 16 ); 17 let my_string: String = "Try to make this a String".into(); 18 println!("{my_string}"); 19 } 20
결과
cargo run Compiling training_rustacean_rust v0.1.0 (/Users/globalyoung/Documents/Project/Github/rust_project/training_rustacean_rust) warning: unused variable: `together` --> src/main.rs:13:9 | 13 | let together = format!( | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_together` | = note: `#[warn(unused_variables)]` on by default warning: `training_rustacean_rust` (bin "training_rustacean_rust") generated 1 warning Finished dev [unoptimized + debuginfo] target(s) in 0.08s Running `target/debug/training_rustacean_rust` &str Try to make this a String
출처 :
https://users.rust-lang.org/t/how-check-type-of-variable/33845
코딩 예문(easy_rust)
https://dhghomon.github.io/easy_rust/Chapter_14.html
반응형'코딩Coding > ★Rust★기초★Syntax' 카테고리의 다른 글
rust] 유형변경#[repr(C)] (0) 2022.04.22 rust Std)align_of & size_of (0) 2022.04.22 Rust] Const vs static (0) 2022.04.20 Rust 3D Tutorial)❤️Rust 3D Graphics⭐️In the Browser : 2D Graphics - Doug Milford (0) 2022.04.20 Rust] Convert string::String to &’static str (0) 2022.04.20 rust crates 그림으로 이해 하기 (0) 2022.04.20 121❤️Easy Rust in Korean: Add trait★❤️ (0) 2022.04.19 Rust) 입문 가이드❤️ -Rust오랫동안하신 선배님시군요 :) 記可爲學 (0) 2022.04.19