identity_cast

Crates.ioidentity_cast
lib.rsidentity_cast
version1.0.0
sourcesrc
created_at2021-08-14 13:58:55.41876
updated_at2021-08-14 13:58:55.41876
descriptionA library for specializing on types dynamically via `Any`
homepage
repositoryhttps://github.com/Kimundi/identity_cast
max_upload_size
id436250
size16,386
Marvin Löbel (Kimundi)

documentation

https://docs.rs/identity_cast/

README

This library provides functions for specializing on types dynamically via Any. The basic idea is that it allows you to "cast" any T into any other U, if T and U are actually the same type.

This is exposed both as freestanding functions, as well as an extension trait that can be imported.

Example

use identity_cast::IdentityCast;

fn print_i32_specially<T: 'static>(v: T) {
    match v.into_same::<i32>() {
        Ok(v) => {
            println!("This is a `i32` with value {}", v);
        }
        Err(_) => {
            println!("This is some `T`");
        }
    }
}
Commit count: 1

cargo fmt