6 releases
0.1.5 | Dec 29, 2024 |
---|---|
0.1.4 | Dec 29, 2024 |
0.1.0 | Dec 29, 2023 |
#2478 in Rust patterns
1,207 downloads per month
Used in 13 crates
(2 directly)
7KB
74 lines
slice_trait
A trait for any slice, with item as an associated type.
This crate is a subset of the crate slice_ops
.
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));