MCPcopy Create free account
hub / github.com/hashintel/hash / fill_until

Method fill_until

libs/@local/hashql/core/src/id/vec.rs:406–414  ·  view source on GitHub ↗

Ensures the vector is at least long enough to contain `index`, filling with `fill` as needed. Returns a mutable reference to the element at `index`. If the vector is too short, it is extended by calling `fill` repeatedly until it contains `index`. # Examples ``` # use hashql_core::id::{IdVec, Id as _, newtype}; # newtype!(struct MyId(u32 is 0..=100)); let mut vec = IdVec:: ::new(); le

(&mut self, index: I, fill: impl FnMut() -> T)

Source from the content-addressed store, hash-verified

404 /// assert_eq!(vec[MyId::new(5)], 42);
405 /// ```
406 pub fn fill_until(&mut self, index: I, fill: impl FnMut() -> T) -> &mut T {
407 let new_length = index.as_usize() + 1;
408
409 if self.len() < new_length {
410 self.raw.resize_with(new_length, fill);
411 }
412
413 &mut self[index]
414 }
415
416 /// Clears the vector, removing all elements.
417 ///

Callers 11

insertMethod · 0.45
get_or_insert_withMethod · 0.45
insert_type_idMethod · 0.45
populateMethod · 0.45
copy_toMethod · 0.45
remapMethod · 0.45
offset_basic_blocksFunction · 0.45
insertMethod · 0.45
local_mutMethod · 0.45
fill_declFunction · 0.45

Calls 2

as_usizeMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected