| Crates.io | borsh-max-size |
| lib.rs | borsh-max-size |
| version | 0.2.0 |
| created_at | 2023-10-02 23:06:13.362878+00 |
| updated_at | 2024-01-18 22:30:40.998114+00 |
| description | Borsh MaxSize trait |
| homepage | |
| repository | https://github.com/TeleportXYZ/borsh-max-size |
| max_upload_size | |
| id | 990597 |
| size | 5,326 |
A Rust library that provides a MaxSize trait, which gives the maximum size the borsh serialization of a struct or enum could be in bytes. Implementations for simple types and a derive macro are included to make it easy to use with your custom types.
MaxSize trait: Get the maximum borsh serialized size of a type in bytes.MaxSize for your structs and enums.Cargo.toml:[dependencies]
borsh-max-size = "0.1"
borsh-max-size contains optional arrayvec and solana-program features that add support for those libraries.
MaxSize trait in your code:use borsh_max_size::MaxSize;
let max_size = i32::max_size(); // for simple types
assert_eq!(max_size, 4);
MaxSize for your own typesuse borsh_max_size::MaxSize;
#[derive(MaxSize)]
struct MyStruct {
a: i32,
b: u64,
c: [u8; 4]
}
println!("Max size of MyStruct: {}", MyStruct::max_size());
This project is licensed under the MIT License. See the LICENSE.md file for details.