Crates.io | unchecked_unwrap |
lib.rs | unchecked_unwrap |
version | 4.0.0 |
source | src |
created_at | 2018-12-07 16:15:54.763881 |
updated_at | 2022-03-22 09:05:25.03816 |
description | Adds an unchecked version of `unwrap()` and `expect()` to Option and Result. |
homepage | |
repository | https://github.com/daxpedda/unchecked_unwrap/tree/release |
max_upload_size | |
id | 100649 |
size | 30,716 |
Since Rust v1.58 this crate is useless, see:
Adds an unchecked version of unwrap()
and expect()
to Option
and Result
for the Rust programming language. Supports no_std
.
use unchecked_unwrap::UncheckedUnwrap;
let x = Some("air");
assert_eq!(unsafe { x.unchecked_unwrap() }, "air");
let x: Result<u32, &str> = Ok(2);
assert_eq!(unsafe { x.unchecked_unwrap() }, 2);
let x = Some("value");
assert_eq!(unsafe { x.unchecked_expect("the world is ending") }, "value");
let x: Result<u32, &str> = Ok(2);
assert_eq!(unsafe { x.unchecked_expect("the sky is falling down") }, 2);
checked | unchecked |
---|---|
fn test_checked(value: Option<&str>) -> &str {
value.unwrap()
}
|
fn test_unchecked(value: Option<&str>) -> &str {
unsafe { value.unchecked_unwrap() }
}
|
push rax
test rdi, rdi
je .LBB2_1 // panic handler
mov rdx, rsi
mov rax, rdi
pop rcx
ret
|
mov rdx, rsi
mov rax, rdi
ret
|
cfg(debug-assertions)
is enabled.Documentation is available online in the badge links above.
Is as simple as cargo test
and cargo test --release
.
Is as simple as cargo bench
. Currently the nightly version of Rust is needed
for benchmarking.
A sample result from the CI running on Github Actions:
test checked::expect_option ... bench: 798 ns/iter (+/- 90)
test checked::expect_result ... bench: 724 ns/iter (+/- 109)
test checked::unwrap_option ... bench: 802 ns/iter (+/- 52)
test checked::unwrap_result ... bench: 743 ns/iter (+/- 176)
test unchecked::expect_option ... bench: 407 ns/iter (+/- 93)
test unchecked::expect_result ... bench: 374 ns/iter (+/- 48)
test unchecked::unwrap_option ... bench: 345 ns/iter (+/- 53)
test unchecked::unwrap_result ... bench: 407 ns/iter (+/- 22)
Both alternatives and this crate are quite the same except that this crate provides additional features that can be toggled with cargo features. See crate features for details.
See the CHANGELOG file for details
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.