MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / array_visit

Function array_visit

crates/sats/src/de.rs:773–784  ·  view source on GitHub ↗

A basic implementation of `ArrayVisitor::visit` using the provided size hint.

(mut access: A)

Source from the content-addressed store, hash-verified

771
772/// A basic implementation of `ArrayVisitor::visit` using the provided size hint.
773pub fn array_visit<'de, A: ArrayAccess<'de>, V: GrowingVec<A::Element>>(mut access: A) -> Result<V, A::Error> {
774 // Don’t blindly trust length prefixes when reserving initial capacity
775 // for decoding array elements, as malformed input could generate a huge allocation,
776 // potentially resulting in an OOM kill.
777 const RESERVE_ARRAY_ELEMENTS: usize = 4096;
778 let cap = access.size_hint().unwrap_or(0);
779 let mut v = V::try_with_capacity(cap.min(RESERVE_ARRAY_ELEMENTS))?;
780 while let Some(x) = access.next_element()? {
781 v.push(x)
782 }
783 Ok(v)
784}
785
786/// A basic implementation of `ArrayVisitor::validate`.
787pub fn array_validate<'de, A: ArrayAccess<'de>>(mut access: A) -> Result<(), A::Error> {

Callers 1

visitMethod · 0.85

Calls 5

unwrap_orMethod · 0.80
OkFunction · 0.50
size_hintMethod · 0.45
next_elementMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…