MCPcopy Create free account
hub / github.com/SoftbearStudios/bitcode / encode

Method encode

src/derive/mod.rs:83–91  ·  view source on GitHub ↗

Like [`encode`], but saves allocations between calls.

(&'a mut self, t: &T)

Source from the content-addressed store, hash-verified

81impl crate::buffer::Buffer {
82 /// Like [`encode`], but saves allocations between calls.
83 pub fn encode<'a, T: Encode + ?Sized>(&'a mut self, t: &T) -> &'a [u8] {
84 // Safety: Encoders don't have any lifetimes (they don't contain T either).
85 let encoder = unsafe { self.registry.get_non_static::<T::Encoder>() };
86 encoder.reserve(NonZeroUsize::new(1).unwrap());
87 encode_inline_never(encoder, t);
88 self.out.clear();
89 encoder.collect_into(&mut self.out);
90 self.out.as_slice()
91 }
92
93 /// Like [`decode`], but saves allocations between calls.
94 pub fn decode<'a, T: Decode<'a>>(&mut self, mut bytes: &'a [u8]) -> Result<T, Error> {

Callers 4

bench_bitcode_encodeFunction · 0.45
bench_bitcode_decodeFunction · 0.45
encode_vectoredMethod · 0.45
encode_inline_neverFunction · 0.45

Calls 5

encode_inline_neverFunction · 0.85
clearMethod · 0.80
as_sliceMethod · 0.80
reserveMethod · 0.45
collect_intoMethod · 0.45

Tested by

no test coverage detected