solana_borsh/
deprecated.rs

1//! Utilities for the [borsh] serialization format.
2//!
3//! To avoid backwards-incompatibilities when the Solana SDK changes its dependency
4//! on borsh, it's recommended to instead use the version-specific file directly,
5//! ie. `v0_10`.
6//!
7//! This file remains for developers who use these borsh helpers, but it will
8//! be removed in a future release
9//!
10//! [borsh]: https://borsh.io/
11use borsh0_10::{maybestd::io::Error, BorshDeserialize, BorshSchema, BorshSerialize};
12
13/// Get the worst-case packed length for the given BorshSchema
14///
15/// Note: due to the serializer currently used by Borsh, this function cannot
16/// be used on-chain in the Solana SBF execution environment.
17#[deprecated(since = "1.17.0", note = "Please use `v0_10::get_packed_len` instead")]
18pub fn get_packed_len<S: BorshSchema>() -> usize {
19    #[allow(deprecated)]
20    crate::v0_10::get_packed_len::<S>()
21}
22
23/// Deserializes without checking that the entire slice has been consumed
24///
25/// Normally, `try_from_slice` checks the length of the final slice to ensure
26/// that the deserialization uses up all of the bytes in the slice.
27///
28/// Note that there is a potential issue with this function. Any buffer greater than
29/// or equal to the expected size will properly deserialize. For example, if the
30/// user passes a buffer destined for a different type, the error won't get caught
31/// as easily.
32#[deprecated(
33    since = "1.17.0",
34    note = "Please use `v0_10::try_from_slice_unchecked` instead"
35)]
36pub fn try_from_slice_unchecked<T: BorshDeserialize>(data: &[u8]) -> Result<T, Error> {
37    #[allow(deprecated)]
38    crate::v0_10::try_from_slice_unchecked::<T>(data)
39}
40
41/// Get the packed length for the serialized form of this object instance.
42///
43/// Useful when working with instances of types that contain a variable-length
44/// sequence, such as a Vec or HashMap.  Since it is impossible to know the packed
45/// length only from the type's schema, this can be used when an instance already
46/// exists, to figure out how much space to allocate in an account.
47#[deprecated(
48    since = "1.17.0",
49    note = "Please use `v0_10::get_instance_packed_len` instead"
50)]
51pub fn get_instance_packed_len<T: BorshSerialize>(instance: &T) -> Result<usize, Error> {
52    #[allow(deprecated)]
53    crate::v0_10::get_instance_packed_len(instance)
54}