rusty-typesh

Crates.iorusty-typesh
lib.rsrusty-typesh
version0.1.1
sourcesrc
created_at2024-12-14 09:54:04.726499+00
updated_at2024-12-14 12:00:05.476476+00
descriptionA flexible type pattern matching system for Rust
homepagehttps://github.com/rusty-libraries/rusty-typesh
repositoryhttps://github.com/rusty-libraries/rusty-typesh
max_upload_size
id1483026
size38,718
bufferization (24rr)

documentation

https://rusty-libraries.github.io/rusty-typesh/

README

Rusty TypeSh - Type Pattern Matching Crates.io docs.rs License

Welcome to Rusty TypeSh, a flexible type pattern matching system for Rust. This library provides a convenient way to perform runtime type checking and pattern matching with custom handlers.

Table of Contents

Installation

To use this library, add the following dependencies to your Cargo.toml file:

[dependencies]
rusty-typesh = "0.1.1"

Getting Started

To get started with Rusty TypeSh, follow these steps:

Basic Type Matching

Use the type_match! macro for simple type matching:

use rusty_typesh::type_match;

let value = 42i32;
let result = type_match!(
    value,
    i32 => |x: &i32| format!("Got integer: {}", x),
    String => |x: &String| format!("Got string: {}", x)
);
assert_eq!(result, Some("Got integer: 42".to_string()));

Custom Type Matching

For more control, use the manual type matching approach:

use rusty_typesh::{TypeMatcher, TypePattern};

let value = 42i32;
let patterns: Vec<(Box<dyn TypePattern<i32>>, Box<dyn Fn(&i32) -> String>)> = vec![
    (
        Box::new(TypeMatcher::<i32>::new()),
        Box::new(|x: &i32| format!("Integer: {}", x)),
    ),
];

let result = rusty_typesh::match_type(&value, &patterns);
assert_eq!(result, Some("Integer: 42".to_string()));

Documentation

For detailed information on all available features and their usage, please refer to the full SDK Documentation.

License

This library is licensed under the MIT License. For more details, see the LICENSE file.

Commit count: 4

cargo fmt