#slice #traits #generic #no-alloc

nightly no-std slice_trait

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

30 releases

Uses new Rust 2024

0.3.14 Dec 21, 2025
0.3.13 Dec 21, 2025
0.3.9 Nov 11, 2025
0.2.5 Oct 25, 2025
0.1.0 Dec 29, 2023

#2467 in Rust patterns

Download history 148/week @ 2026-02-12 195/week @ 2026-02-19 220/week @ 2026-02-26 230/week @ 2026-03-05 182/week @ 2026-03-12 158/week @ 2026-03-19 173/week @ 2026-03-26 178/week @ 2026-04-02 160/week @ 2026-04-09 174/week @ 2026-04-16 155/week @ 2026-04-23 147/week @ 2026-04-30 126/week @ 2026-05-07 188/week @ 2026-05-14 154/week @ 2026-05-21 166/week @ 2026-05-28

653 downloads per month
Used in 14 crates (2 directly)

MIT license

25KB
676 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));

Dependencies

~22KB