-
Rust Type을 알아보기(The Any trait) JS의Typeof와 비슷한 개념코딩Coding/★Rust★기초★Syntax 2022. 4. 4. 21:26728x90
use std::any::{type_name, Any}; use std::collections::HashMap; fn get_type_name<T: Any>(input: T) { let my_type = type_name::<T>(); println!("{my_type}"); } fn main() { let map = HashMap::from([("a", 1), ("b", 2), ("c", 3)]); get_type_name(map); }
https://doc.rust-lang.org/std/any/fn.type_name.html
https://doc.rust-lang.org/nightly/std/any/trait.Any.html#method.downcast_ref
반응형'코딩Coding > ★Rust★기초★Syntax' 카테고리의 다른 글
Calculating Pi: Rust❤️vs Python vs PyO3 vs c++ (0) 2022.04.05 The Ray Tracer Challenge #027- Tauri App (0) 2022.04.05 5 Tips for Rust❤️Beginners❤️ (0) 2022.04.05 Rust Project:❤️ Deserialization with Serde❤️cargo test -- --nocapture (0) 2022.04.04 Rust Intermediate Tutorial #1 - Rust and❤️ Docker (0) 2022.04.04 RustLab 2021 (0) 2022.04.04 The Rust Borrow Checker- A Deep Dive - Nell Shamrell-Harrington, Microsoft (0) 2022.04.04 Rust의 채널(Channel)의 의미는 Confluence라고 생각해야한다.channel in std::sync::mpsc (0) 2022.04.03