Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
B

bytes

> 编程语言
Open source

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

385 stars0 likes1 views
WebsiteGitHub

About

Wrapper types to enable optimized handling of &[u8] and 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 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rust

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

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