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

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,870 questions

51,793 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>

*/

 



answered Jul 8, 2024 by avibootz

Related questions

1 answer 111 views
1 answer 107 views
1 answer 95 views
1 answer 95 views
1 answer 122 views
122 views asked Dec 27, 2022 by avibootz
1 answer 101 views
101 views asked Dec 27, 2022 by avibootz
1 answer 130 views
130 views asked May 22, 2023 by avibootz
...