百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
B

bytes

> 编程语言
开源

添加 Wrapper 类型,以优化对 &[u8] 和 Vec<u8> 的处理

385 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

添加 Wrapper 类型,以优化对 &[u8] 和 Vec<u8> 的处理

serde_bytes

Wrapper types to enable optimized handling of &[u8] and Vec.

toml
[dependencies]
serde_bytes = "0.11"

Explanation

Without specialization, Rust forces Serde to treat &[u8] just like any other slice and Vec just like any other vector. In reality this particular slice and vector can often be serialized and deserialized in a more efficient, compact representation in many formats.

When working with such a format, you can opt into specialized handling of &[u8] by wrapping it in serde_bytes::Bytes and Vec by wrapping it in serde_bytes::ByteBuf.

Additionally this crate supports the Serde with attribute to enable efficient handling of &[u8] and Vec in structs without needing a wrapper type.

Example

rust
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize)]
struct Efficient {
    #[serde(with = "serde_bytes")]
    bytes: &'a [u8],

    #[serde(with = "serde_bytes")]
    byte_buf: Vec,
}

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rust

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言