#slice #traits #generic #no-alloc

nightly no-std slice_trait

A generic trait for any slice, with item as a type parameter

6 releases

0.1.5 Dec 29, 2024
0.1.4 Dec 29, 2024
0.1.0 Dec 29, 2023

#2478 in Rust patterns

Download history 37/week @ 2024-09-27 11/week @ 2024-10-04 19/week @ 2024-10-11 18/week @ 2024-10-18 12/week @ 2024-10-25 26/week @ 2024-11-01 11/week @ 2024-11-15 24/week @ 2024-11-22 46/week @ 2024-11-29 124/week @ 2024-12-06 455/week @ 2024-12-13 144/week @ 2024-12-20 717/week @ 2024-12-27 151/week @ 2025-01-03 123/week @ 2025-01-10

1,207 downloads per month
Used in 13 crates (2 directly)

MIT license

7KB
74 lines

Build Status (nightly)

Build Status (stable)

Test Status Lint Status

Latest Version License:MIT Documentation Coverage Status

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));

No runtime deps