Crates.io | bitcode |
lib.rs | bitcode |
version | 0.6.3 |
source | src |
created_at | 2023-04-16 04:55:41.893557 |
updated_at | 2024-07-14 20:12:46.407535 |
description | bitcode is a bitwise binary serializer |
homepage | |
repository | https://github.com/SoftbearStudios/bitcode |
max_upload_size | |
id | 840349 |
size | 267,568 |
A binary encoder/decoder with the following goals:
In contrast, these are non-goals:
See rust_serialization_benchmark for benchmarks.
use bitcode::{Encode, Decode};
#[derive(Encode, Decode, PartialEq, Debug)]
struct Foo<'a> {
x: u32,
y: &'a str,
}
let original = Foo {
x: 10,
y: "abc",
};
let encoded: Vec<u8> = bitcode::encode(&original); // No error
let decoded: Foo<'_> = bitcode::decode(&encoded).unwrap();
assert_eq!(original, decoded);
Add bitcode to libraries without specifying the major version so binary crates can pick the version. This is a minimal stable subset of the bitcode API so avoid using any other functionality.
bitcode = { version = "0", features = ["derive"], default-features = false, optional = true }
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
pub struct Vec2 {
x: f32,
y: f32,
}
If you have multiple values of the same type:
x: u32, y: u32
pixels: [u8; 16]
#![no_std]
All std
-only functionality is gated behind the (default) "std"
feature.
alloc
is required.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.