konst::option

Function copied

Source
pub const fn copied<T: Copy>(opt: Option<&T>) -> Option<T>
Expand description

A const equivalent of the Option::copied method.

§Const stabilization

The equivalent std function was const-stabilized in Rust 1.83.0.

§Example

use konst::option;

const fn get_last(slice: &[u64]) -> Option<u64> {
    option::copied(slice.last())
}

assert_eq!(get_last(&[]), None);
assert_eq!(get_last(&[16]), Some(16));
assert_eq!(get_last(&[3, 5, 8, 13]), Some(13));