Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUST

How to know the data type in rust

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

fn main() {
    let s = "Hello";
    let i = 42;

    print_type_of(&s); // &str
    print_type_of(&i); // i32
    print_type_of(&main); // playground::main
    print_type_of(&print_type_of::<i32>); // playground::print_type_of<i32>
    print_type_of(&{ || "Hi!" }); // playground::main::{{closure}}
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #How #data #type #rust
ADD COMMENT
Topic
Name
3+5 =