Crates.io | unty |
lib.rs | unty |
version | |
source | src |
created_at | 2023-09-23 13:21:59.316884+00 |
updated_at | 2025-03-07 08:06:25.562232+00 |
description | Explicitly types your generics |
homepage | |
repository | https://github.com/bincode-org/unty |
max_upload_size | |
id | 981232 |
Cargo.toml error: | TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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
}
This crate is dual licenced MIT and Apache-2.0, at your own leisure