| 1 | #![cfg_attr (not(feature = "std" ), no_std)] |
| 2 | #![doc = include_str!("../docs/rustdoc_include/borsh_crate_top_level.md" )] |
| 3 | |
| 4 | #[cfg (not(feature = "std" ))] |
| 5 | extern crate alloc; |
| 6 | |
| 7 | #[doc = include_str!("../docs/rustdoc_include/borsh_schema.md" )] |
| 8 | #[cfg (feature = "unstable__schema" )] |
| 9 | pub use borsh_derive::BorshSchema; |
| 10 | |
| 11 | #[doc = include_str!("../docs/rustdoc_include/borsh_deserialize.md" )] |
| 12 | #[cfg (feature = "derive" )] |
| 13 | pub use borsh_derive::BorshDeserialize; |
| 14 | |
| 15 | #[doc = include_str!("../docs/rustdoc_include/borsh_serialize.md" )] |
| 16 | #[cfg (feature = "derive" )] |
| 17 | pub use borsh_derive::BorshSerialize; |
| 18 | |
| 19 | pub mod de; |
| 20 | |
| 21 | // See `hash_collections` alias definition in build.rs |
| 22 | /// Module is available if borsh is built with `features = ["unstable__schema"]`. |
| 23 | #[cfg (feature = "unstable__schema" )] |
| 24 | pub mod schema; |
| 25 | #[cfg (feature = "unstable__schema" )] |
| 26 | pub(crate) mod schema_helpers; |
| 27 | pub mod ser; |
| 28 | |
| 29 | pub use de::BorshDeserialize; |
| 30 | pub use de::{from_reader, from_slice}; |
| 31 | #[cfg (feature = "unstable__schema" )] |
| 32 | pub use schema::BorshSchema; |
| 33 | #[cfg (feature = "unstable__schema" )] |
| 34 | pub use schema_helpers::{ |
| 35 | max_serialized_size, schema_container_of, try_from_slice_with_schema, try_to_vec_with_schema, |
| 36 | }; |
| 37 | pub use ser::helpers::{object_length, to_vec, to_writer}; |
| 38 | pub use ser::BorshSerialize; |
| 39 | pub mod error; |
| 40 | |
| 41 | #[cfg (all(feature = "std" , feature = "hashbrown" ))] |
| 42 | compile_error!("feature \"std \" and feature \"hashbrown \" don't make sense at the same time" ); |
| 43 | |
| 44 | #[cfg (feature = "std" )] |
| 45 | use std::io as io_impl; |
| 46 | #[cfg (not(feature = "std" ))] |
| 47 | mod nostd_io; |
| 48 | #[cfg (not(feature = "std" ))] |
| 49 | use nostd_io as io_impl; |
| 50 | |
| 51 | /// Subset of `std::io` which is used as part of borsh public API. |
| 52 | /// |
| 53 | /// When crate is built with `std` feature disabled (it’s enabled by default), |
| 54 | /// the exported types are custom borsh types which try to mimic behaviour of |
| 55 | /// corresponding standard types usually offering subset of features. |
| 56 | pub mod io { |
| 57 | pub use super::io_impl::{Error, ErrorKind, Read, Result, Write}; |
| 58 | } |
| 59 | |
| 60 | #[doc (hidden)] |
| 61 | pub mod __private { |
| 62 | |
| 63 | /// A facade around all the types we need from the `std`, and `alloc` |
| 64 | /// crates. This avoids elaborate import wrangling having to happen in every |
| 65 | /// module. |
| 66 | #[cfg (feature = "std" )] |
| 67 | pub mod maybestd { |
| 68 | pub use std::{borrow, boxed, collections, format, string, vec}; |
| 69 | |
| 70 | #[cfg (feature = "rc" )] |
| 71 | pub use std::{rc, sync}; |
| 72 | } |
| 73 | #[cfg (not(feature = "std" ))] |
| 74 | pub mod maybestd { |
| 75 | pub use alloc::{borrow, boxed, format, string, vec}; |
| 76 | |
| 77 | #[cfg (feature = "rc" )] |
| 78 | pub use alloc::{rc, sync}; |
| 79 | |
| 80 | pub mod collections { |
| 81 | pub use alloc::collections::{btree_map, BTreeMap, BTreeSet, LinkedList, VecDeque}; |
| 82 | #[cfg (feature = "hashbrown" )] |
| 83 | pub use hashbrown::*; |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |