MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / try_with_capacity

Method try_with_capacity

cranelift/entity/src/map.rs:72–85  ·  view source on GitHub ↗

Like `with_capacity` but returns an error on allocation failure.

(capacity: usize)

Source from the content-addressed store, hash-verified

70
71 /// Like `with_capacity` but returns an error on allocation failure.
72 pub fn try_with_capacity(capacity: usize) -> Result<Self, OutOfMemory>
73 where
74 V: Default,
75 {
76 let mut elems = Vec::new();
77 elems
78 .try_reserve(capacity)
79 .map_err(|_| OutOfMemory::new(core::mem::size_of::<V>().saturating_mul(capacity)))?;
80 Ok(Self {
81 elems,
82 default: Default::default(),
83 unused: PhantomData,
84 })
85 }
86
87 /// Create a new empty map with a specified default value.
88 ///

Callers

nothing calls this directly

Calls 3

OkFunction · 0.85
try_reserveMethod · 0.80
newFunction · 0.50

Tested by

no test coverage detected