#slice #tagged-pointers #pointers #tagged

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

#308 in Memory management

Download history 50828/week @ 2024-07-20 51968/week @ 2024-07-27 51630/week @ 2024-08-03 56367/week @ 2024-08-10 53613/week @ 2024-08-17 56803/week @ 2024-08-24 60615/week @ 2024-08-31 54764/week @ 2024-09-07 52024/week @ 2024-09-14 52352/week @ 2024-09-21 62365/week @ 2024-09-28 61237/week @ 2024-10-05 61567/week @ 2024-10-12 61074/week @ 2024-10-19 62926/week @ 2024-10-26 62074/week @ 2024-11-02

256,988 downloads per month
Used in 645 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