#validation #conversion #datatype #utility

data_type_checker

A lightweight Rust library for validating and converting data types from strings

5 releases

0.1.4 Nov 21, 2024
0.1.3 Nov 10, 2024
0.1.2 Nov 10, 2024
0.1.1 Oct 31, 2024
0.1.0 Oct 29, 2024

#1471 in Rust patterns

Download history 211/week @ 2024-10-25 48/week @ 2024-11-01 168/week @ 2024-11-08 130/week @ 2024-11-15 41/week @ 2024-11-22 3/week @ 2024-11-29 3/week @ 2024-12-06

181 downloads per month

MIT license

6KB
66 lines

data_type_checker

data_type_checker is a lightweight Rust library for validating and converting string data into different data types, making it easy to handle dynamic inputs in your applications.

Installation

Add data_type_checker to your Cargo.toml:

[dependencies]
data_type_checker = "0.1.0"```

## Usage
```rust
use data_type_checker::TypeChecker;

fn main() {
    let num_str = "42";

    if TypeChecker::is_int(num_str) {
        println!("'{}' is an integer!", num_str);
    }

    if let Some(value) = TypeChecker::to_int(num_str) {
        println!("Parsed integer: {}", value);
    }
}

Features

is_int: Checks if a string can be parsed as an integer. is_float: Checks if a string can be parsed as a float. is_bool: Checks if a string represents a boolean. to_int: Attempts to parse a string into an integer, returning None if it fails. to_float: Attempts to parse a string into a float, returning None if it fails. to_bool: Attempts to parse a string into a boolean, returning None if it fails.

License

This project is licensed under the MIT License

Author

bensatlantik

No runtime deps