#slice #traits #generic #no-alloc

nightly no-std slice_trait

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

11 releases

0.2.0 Feb 16, 2025
0.1.9 Feb 5, 2025
0.1.5 Dec 29, 2024
0.1.0 Dec 29, 2023

#2230 in Rust patterns

Download history 15/week @ 2024-11-17 32/week @ 2024-11-24 39/week @ 2024-12-01 190/week @ 2024-12-08 424/week @ 2024-12-15 262/week @ 2024-12-22 599/week @ 2024-12-29 154/week @ 2025-01-05 132/week @ 2025-01-12 138/week @ 2025-01-19 124/week @ 2025-01-26 747/week @ 2025-02-02 202/week @ 2025-02-09 266/week @ 2025-02-16 113/week @ 2025-02-23 106/week @ 2025-03-02

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

MIT license

10KB
178 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

~20KB