borsh-rs is Rust implementation of the [Borsh] binary serialization format.
Borsh stands for Binary Object Representation Serializer for Hashing. It is meant to be used in security-critical projects as it prioritizes consistency, safety, speed, and comes with a strict specification.
```rust use borsh::{BorshSerialize, BorshDeserialize};
struct A { x: u64, y: String, }
fn testsimplestruct() { let a = A { x: 3301, y: "liber primus".tostring(), }; let encodeda = a.trytovec().unwrap(); let decodeda = A::tryfromslice(&encodeda).unwrap(); asserteq!(a, decodeda); } ```
Opting out from Serde allows borsh to have some features that currently are not available for serde-compatible serializers.
Currently we support two features: borsh_init
and borsh_skip
(the former one not available in Serde).
borsh_init
allows to automatically run an initialization function right after deserialization. This adds a lot of convenience for objects that are architectured to be used as strictly immutable. Usage example:
```rust
struct Message { message: String, timestamp: u64, public_key: CryptoKey, signature: CryptoSignature hash: CryptoHash }
impl Message { pub fn init(&mut self) { self.hash = CryptoHash::new().writestring(self.message).writeu64(self.timestamp); self.signature.verify(self.hash, self.public_key); } } ```
borsh_skip
allows to skip serializing/deserializing fields, assuming they implement Default
trait, similary to #[serde(skip)]
.
```rust
struct A { x: u64, #[borsh_skip] y: f32, } ```
Before you release, make sure CHANGELOG.md is up to date.
Use cargo-workspaces
to save time.
sh
cargo workspaces version --force 'borsh*' --exact --no-individual-tags patch
This will bump all the versions to the next "patch" release (see cargo workspaces version --help
for more options), create a new commit, push v0.x.x
tag, push to the master.
To publish on crates.io the version that is currently in git:
sh
cargo workspaces publish --from-git --skip-published
Alternatively, you may want to combine the version bumping with publishing:
sh
cargo workspaces publish --force 'borsh*' --exact --no-individual-tags patch
v0.8.0
This repository is distributed under the terms of both the MIT license and the Apache License (Version 2.0). See LICENSE-MIT and LICENSE-APACHE for details.