Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Semrush - keyword research tool

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Teach Your Child To Read

Disclosure: My content contains affiliate links.

31,647 questions

41,700 answers

573 users

How to check the data type of a variable in Rust

1 Answer

0 votes
fn print_type_of<T>(_: &T) {
    println!("{}", std::any::type_name::<T>())
}

fn main() {
    let a = "Rust";
    let b = 42;
    let c = 3.14;
    let d = false;
    let e: f32 = 787.007;
    let f: i8 = 12;
    let g: char = 'a';
    let h = vec!['r', 'u', 's', 't'];
    
    print_type_of(&a); 
    print_type_of(&b); 
    print_type_of(&c); 
    print_type_of(&d); 
    print_type_of(&e); 
    print_type_of(&f); 
    print_type_of(&g); 
    print_type_of(&h); 
}



/*
run:

&str
i32
f64
bool
f32
i8
char
alloc::vec::Vec<char>

*/

 



Learn & Practice Python
with the most comprehensive set of 13 hands-on online Python courses
Start now


answered Jul 8 by avibootz

Related questions

1 answer 48 views
48 views asked Dec 27, 2022 by avibootz
1 answer 32 views
32 views asked Dec 27, 2022 by avibootz
1 answer 43 views
43 views asked May 22, 2023 by avibootz
1 answer 44 views
...