identity_cast 1.0.0

A library for specializing on types dynamically via `Any`
Documentation
  • Coverage
  • 87.5%
    7 out of 8 items documented1 out of 8 items with examples
  • Size
  • Source code size: 16.38 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 276.94 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Kimundi/identity_cast
    3 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Kimundi

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`");
        }
    }
}