#tagged-pointers #slice #tagged #pointers #mem #thin-boxed-slice

thin-slice

An owned slice that packs the slice storage into a single word when possible

2 releases

Uses old Rust 2015

0.1.1 Jul 17, 2018
0.1.0 Jul 17, 2018

#1698 in Rust patterns

Download history 52632/week @ 2024-12-27 73155/week @ 2025-01-03 67898/week @ 2025-01-10 69978/week @ 2025-01-17 80296/week @ 2025-01-24 71387/week @ 2025-01-31 77355/week @ 2025-02-07 74666/week @ 2025-02-14 82875/week @ 2025-02-21 78473/week @ 2025-02-28 77928/week @ 2025-03-07 83307/week @ 2025-03-14 79113/week @ 2025-03-21 82730/week @ 2025-03-28 81829/week @ 2025-04-04 79054/week @ 2025-04-11

336,426 downloads per month
Used in 709 crates (via graphannis-malloc_size_of)

MPL-2.0 license

19KB
334 lines

thin-slice

An owned slice that packs the slice storage into a single word when possible.

Usage

extern crate thin_slice;

use std::mem;
use thin_slice::ThinBoxedSlice;

struct Ticket {
    numbers: Box<[u8]>,
    winning: bool,
}

struct ThinTicket {
    numbers: ThinBoxedSlice<u8>,
    winning: bool,
}

fn main() {
    let nums = vec![4, 8, 15, 16, 23, 42].into_boxed_slice();
    let ticket = ThinTicket {
        numbers: nums.into(),
        winning: false,
    };
    println!("Numbers: {:?}", ticket.numbers);

    println!("size_of::<usize>():      {}", mem::size_of::<usize>());
    println!("size_of::<Ticket>():     {}", mem::size_of::<Ticket>());
    println!("size_of::<ThinTicket>(): {}", mem::size_of::<ThinTicket>());
}

Output on x86_64:

Numbers: [4, 8, 15, 16, 23, 42]
size_of::<usize>():      8
size_of::<Ticket>():     24
size_of::<ThinTicket>(): 16

License

thin-slice is distributed under the terms of the Mozilla Public License, v. 2.0.

No runtime deps