#slice #traits #generic #no-alloc

nightly no-std slice_trait

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

11 releases

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

#2180 in Rust patterns

Download history 24/week @ 2024-10-29 8/week @ 2024-11-05 2/week @ 2024-11-12 24/week @ 2024-11-19 36/week @ 2024-11-26 32/week @ 2024-12-03 367/week @ 2024-12-10 293/week @ 2024-12-17 704/week @ 2024-12-24 155/week @ 2024-12-31 143/week @ 2025-01-07 136/week @ 2025-01-14 132/week @ 2025-01-21 124/week @ 2025-01-28 783/week @ 2025-02-04 282/week @ 2025-02-11

1,347 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