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,872 questions

51,796 answers

573 users

How to find variable type in Rust

1 Answer

0 votes
fn main() {
    let str = "rust";
    let number = 435;
    let pi = 3.14;
    let f: f32 = 87.341; 
    let ch = 'a';
    let b = true;
    let tpl: (u32, i64, f32) = (12, -74, 1.057);
    let array = [1, 2, 3, 4, 5, 6];
    let vec = vec![1, 2, 3, 4];

    print_type(&str); 
    print_type(&number); 
    print_type(&pi); 
    print_type(&f); 
    print_type(&ch); 
    print_type(&b); 
    print_type(&tpl); 
    print_type(&array); 
    print_type(&vec); 
    print_type(&main); 
}

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





/*
run:

&str
i32
f64
f32
char
bool
(u32, i64, f32)
[i32; 6]
alloc::vec::Vec<i32>
test::main

*/

 



answered May 22, 2023 by avibootz
...