#slice #pointers #tagged-pointers #tagged

thin-slice

尽可能将切片存储打包到一个单词中的自有切片

2 个版本

使用旧的 Rust 2015

0.1.1 2018 年 7 月 17 日
0.1.0 2018 年 7 月 17 日

1776Rust 模式

Download history 41804/week @ 2024-03-24 41757/week @ 2024-03-31 39026/week @ 2024-04-07 40478/week @ 2024-04-14 39620/week @ 2024-04-21 37140/week @ 2024-04-28 41427/week @ 2024-05-05 41387/week @ 2024-05-12 42531/week @ 2024-05-19 43353/week @ 2024-05-26 46054/week @ 2024-06-02 42849/week @ 2024-06-09 47874/week @ 2024-06-16 45476/week @ 2024-06-23 48454/week @ 2024-06-30 48785/week @ 2024-07-07

194,981 每月下载量
588 个crate中使用(通过 graphannis-malloc_size_of

MPL-2.0 许可证

19KB
334

thin-slice

尽可能将切片存储打包到一个单词中的自有切片。

用法

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>());
}

输出在 x86_64

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

许可证

thin-slice 根据 Mozilla 公共许可证,第 2.0 版 进行分发。

无运行时依赖