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

Method try_insert

cranelift/entity/src/map.rs:120–129  ·  view source on GitHub ↗

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

(&mut self, k: K, v: V)

Source from the content-addressed store, hash-verified

118
119 /// Like `insert` but returns an error on allocation failure.
120 pub fn try_insert(&mut self, k: K, v: V) -> Result<Option<V>, OutOfMemory> {
121 let i = k.index();
122 if i < self.elems.len() {
123 Ok(Some(core::mem::replace(&mut self.elems[i], v)))
124 } else {
125 self.try_resize(i + 1)?;
126 self.elems[i] = v;
127 Ok(None)
128 }
129 }
130
131 /// Remove the element at `k`, if it exists, replacing it with the default
132 /// value.

Callers 8

insertMethod · 0.45
insertMethod · 0.45
or_insert_with_keyMethod · 0.45
insert_entryMethod · 0.45
insertMethod · 0.45
bforest_mapFunction · 0.45
bforest_setFunction · 0.45
secondary_map_try_insertFunction · 0.45

Calls 5

OkFunction · 0.85
try_resizeMethod · 0.80
replaceFunction · 0.50
indexMethod · 0.45
lenMethod · 0.45

Tested by 3

bforest_mapFunction · 0.36
bforest_setFunction · 0.36
secondary_map_try_insertFunction · 0.36