#slice #traits #generic #no-alloc

nightly no-std slice_trait

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

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

Download history 51/week @ 2024-08-26 24/week @ 2024-09-02 22/week @ 2024-09-09 29/week @ 2024-09-16 38/week @ 2024-09-23 39/week @ 2024-09-30 22/week @ 2024-10-14 21/week @ 2024-10-21 16/week @ 2024-10-28 16/week @ 2024-11-04 2/week @ 2024-11-11 23/week @ 2024-11-18 25/week @ 2024-11-25 43/week @ 2024-12-02 204/week @ 2024-12-09

295 downloads per month
Used in 13 crates (2 directly)

MIT license

6KB
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.

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