You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While working on an embedded app, it was discovered, that it's not possible to use borsh crate when global_allocator is not defined.
One possible solution in such cases is to define global_allocator , another is to extract alloc feature and to use borsh with default_features = false .
std = ["alloc"]
# Provide impls for types in the Rust core allocation and collections library
# including String, Box<T>, Vec<T>, and Cow<T>. This is a subset of std but may
# be enabled without depending on all of std.
alloc = []
Below is superficial description of changes required:
extract everything about alloc crate into separate feature
change borsh/src/nostd_io.rs or make 2 variants, depending on alloc feature
make BorshDeserialize trait method vec_from_reader depending on alloc feature
each usage of std::io::Error::new and borsh::io::Error::new implies depending on alloc feature, there's around 50 occurencies of it in borsh
original motivation to create this issue was kind of resolved by LedgerHQ/ledger-device-rust-sdk#155, but the heap on the device was still not quite usable on the device with smallest capabilities, as mentioned in comment , EDIT: support of which (smaller devices) was removed later
With the mentioned tiniest target platform being a concrete example of environment imposing specific requirements, most likely an endeavor to resolve this issue will only make sense together with changing the signature of BorshDeserialize:
fndeserialize(...) -> Result<Self>;
to
fndeserialize(...,&mutself) -> Result<()>;
While working on an embedded app, it was discovered, that it's not possible to use
borsh
crate whenglobal_allocator
is not defined.One possible solution in such cases is to define
global_allocator
, another is to extractalloc
feature and to useborsh
withdefault_features = false
.Below is superficial description of changes required:
alloc
crate into separate featureborsh/src/nostd_io.rs
or make 2 variants, depending onalloc
featureBorshDeserialize
trait methodvec_from_reader
depending onalloc
featurestd::io::Error::new
andborsh::io::Error::new
implies depending onalloc
feature, there's around 50 occurencies of it inborsh
BorshSerialize
unstable__schema
feature implyalloc
featureFor reference an example of replicating a subset of
borsh
without dependency onalloc
crate is provided.The text was updated successfully, but these errors were encountered: