unty

Crates.iounty
lib.rsunty
version0.0.3
sourcesrc
created_at2023-09-23 13:21:59.316884
updated_at2023-09-24 09:09:08.398262
descriptionExplicitly types your generics
homepagehttps://github.com/bincode-org/unty
repository
max_upload_size
id981232
size7,073
Trangar (VictorKoenders)

documentation

README

A crate that allows you to mostly-safely cast one type into another type.

This is mostly useful for generic functions, e.g.

pub fn foo<S>(s: S) {
    if let Ok(a) = unsafe { unty::<S, u8>(s) } {
        println!("It is an u8 with value {a}");
    } else {
        println!("it is not an u8");
    }
}
foo(10u8); // will print "it is an u8"
foo("test"); // will print "it is not an u8"

This operation is still unsafe because it allows you to extend lifetimes. There currently is not a way to prevent this

if let Ok(str) = unsafe { unty::<&'a str, &'static str>(input) } {
    // the compiler may now light your PC on fire
}

License

This crate is dual licenced MIT and Apache-2.0, at your own leisure

Commit count: 0

cargo fmt