#slice #traits #generic #parameters #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

#2972 in Rust patterns

Download history 120/week @ 2025-02-19 138/week @ 2025-02-26 97/week @ 2025-03-05 156/week @ 2025-03-12 120/week @ 2025-03-19 134/week @ 2025-03-26 120/week @ 2025-04-02 93/week @ 2025-04-09 76/week @ 2025-04-16 56/week @ 2025-04-23 57/week @ 2025-04-30 54/week @ 2025-05-07 48/week @ 2025-05-14 32/week @ 2025-05-21 42/week @ 2025-05-28 21/week @ 2025-06-04

153 downloads per month
Used in 10 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