4 releases
new 0.1.3 | Dec 16, 2024 |
---|---|
0.1.2 | Dec 16, 2024 |
0.1.1 | Dec 12, 2024 |
0.1.0 | Dec 29, 2023 |
#2116 in Rust patterns
295 downloads per month
Used in 13 crates
(2 directly)
6KB
74 lines
slice_trait
A trait for any slice, with item as an associated type.
Example
use slice_trait::*;
let a: &[i32] = [1, 2, 3].as_slice();
fn first<'a, S: Slice + ?Sized>(slice: &'a S) -> Option<&'a S::Item>
where
S::Item: Copy,
{
slice.as_slice().first()
}
assert_eq!(first(a), Some(&1));