52 releases (14 stable)

new 1.5.4 Jan 13, 2025
1.5.3 Nov 13, 2024
1.5.1 May 31, 2024
1.4.0 Mar 26, 2024
0.2.10 Nov 27, 2019

#1779 in Encoding

Download history 479270/week @ 2024-09-23 1468475/week @ 2024-09-30 2360978/week @ 2024-10-07 2010719/week @ 2024-10-14 738517/week @ 2024-10-21 413996/week @ 2024-10-28 389945/week @ 2024-11-04 412540/week @ 2024-11-11 424425/week @ 2024-11-18 376127/week @ 2024-11-25 457711/week @ 2024-12-02 430333/week @ 2024-12-09 395662/week @ 2024-12-16 210916/week @ 2024-12-23 264450/week @ 2024-12-30 562573/week @ 2025-01-06

1,460,387 downloads per month
Used in 2,200 crates (52 directly)

Apache-2.0

165KB
4.5K SLoC

Borsh in Rust   Latest Version borsh: rustc 1.67+ License Apache-2.0 badge License MIT badge

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.

Example

use borsh::{BorshSerialize, BorshDeserialize, from_slice, to_vec};

#[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)]
struct A {
    x: u64,
    y: String,
}

#[test]
fn test_simple_struct() {
    let a = A {
        x: 3301,
        y: "liber primus".to_string(),
    };
    let encoded_a = to_vec(&a).unwrap();
    let decoded_a = from_slice::<A>(&encoded_a).unwrap();
    assert_eq!(a, decoded_a);
}

Docs shortcuts

Following pages are highlighted here just to give reader a chance at learning that they exist.

Advanced examples

Some of the less trivial examples are present in examples folder:

Testing

Integration tests should generally be preferred to unit ones. Root module of integration tests of borsh crate is linked here.

Releasing

The versions of all public crates in this repository are collectively managed by a single version in the workspace manifest.

So, to publish a new version of all the crates, you can do so by simply bumping that to the next "patch" version and submit a PR.

We have CI Infrastructure put in place to automate the process of publishing all crates once a version change has merged into master.

However, before you release, make sure the CHANGELOG is up to date and that the [Unreleased] section is present but empty.

License

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.

Dependencies

~1.3–2MB
~39K SLoC