#string #gettype #get-type

gettype

A simple function to get the type of a value at runtime

1 stable release

Uses new Rust 2024

new 1.0.0 Apr 2, 2025

#457 in Debugging

Download history 84/week @ 2025-03-28

84 downloads per month

GPL-3.0-or-later

3KB

gettype

Overview

gettype is a simple Rust crate that provides a function to retrieve the type of a variable as a string, useful for debugging and logging.

How to use

To use this crate, add it as a dependency in your Cargo.toml:

[dependencies]
gettype = "1.0.0"

Example code:

use gettype::get_type;

fn main() -> () {
    let integer  = 42;
    let floating = 3.14;
    let text     = "Hello, Rust!";

    println!("Type of integer: {}", get_type(&integer));
    println!("Type of floating: {}", get_type(&floating));
    println!("Type of text: {}", get_type(&text));
}

Output:

Type of integer: i32
Type of floating: f64
Type of text: &str

No runtime deps