insert_with

Function insert_with 

Source
pub fn insert_with<T, F>(
    component_fn: F,
    mode: InsertMode,
) -> impl EntityCommand
where T: Component, F: FnOnce() -> T + Send + 'static,
Expand description

An EntityCommand that adds a component to an entity using some function that returns the component.

The function will only be invoked if the component will actually be inserted. In other words, the function will not be invoked if mode is InsertMode::Keep and the entity already has the component.