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

Method push_with

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

Appends an element created by calling `value` with the new ID, and returns that ID. This allows creating elements that depend on their own ID. # Examples ``` # use hashql_core::id::{IdVec, Id as _, newtype}; # newtype!(struct MyId(u32 is 0..=100)); let mut vec = IdVec:: ::new(); let id = vec.push_with(|id| format!("item_{}", id.as_u32())); assert_eq!(vec[id], "item_0"); ```

(&mut self, value: impl FnOnce(I) -> T)

Source from the content-addressed store, hash-verified

357 /// assert_eq!(vec[id], "item_0");
358 /// ```
359 pub fn push_with(&mut self, value: impl FnOnce(I) -> T) -> I {
360 let id = self.bound();
361 self.raw.push(value(id));
362 id
363 }
364
365 /// Removes the last element from the vector and returns it, or `None` if empty.
366 ///

Callers 4

add_nodeMethod · 0.80
add_edgeMethod · 0.80
finalize_sccMethod · 0.80
lower_implMethod · 0.80

Calls 3

pushMethod · 0.65
valueFunction · 0.50
boundMethod · 0.45

Tested by

no test coverage detected