3 releases (stable)

1.0.1 Apr 9, 2024
1.0.0 Nov 14, 2023
0.1.0 Sep 3, 2023

#1192 in Parser implementations

Download history 2/week @ 2024-02-15 20/week @ 2024-02-22 7/week @ 2024-02-29 1/week @ 2024-03-21 22/week @ 2024-03-28 124/week @ 2024-04-04 25/week @ 2024-04-11

172 downloads per month
Used in bryte_descriptor_client

MIT license

7KB

borsh-schema-writer

This library provides a function to take a Struct with the BorshSchema trait and writes the schema to a specified file. This file can then be hosted in a registry, file system, database, web storage, etc... for consumers to use. Here is an example:

use std::fs::File;
use std::io::BufReader;
use borsh::{BorshDeserialize, BorshSerialize, BorshSchema};
use borsh::schema::{BorshSchemaContainer, Definition, Fields};
use borsh_schema_writer::schema_writer::write_schema;

#[derive(Debug, Default, BorshSerialize, BorshDeserialize, BorshSchema)]
pub struct Person {
    first_name: String,
    last_name: String
}

fn write_schema_example() {
write_schema(Person::default(), "./tests/schema/person_schema.dat".to_string());
    let file = File::open("./tests/schema/person_schema.dat").unwrap();
    let mut reader = BufReader::new(file);
    let container_from_file = BorshSchemaContainer::deserialize_reader(&mut reader).expect("Deserialization for BorshSchemaContainer failed");
}

Dependencies

~1.6–2.3MB
~47K SLoC