I don't currently have access to my PC to show my code but here's a rough example in C#. For Predicate I used F: Fn(&T) -> bool and Action I used FnMut(&mut T). BoundingSphere I was able to roughly write to Rust already
public void Select(BoundingSphere sphere, Predicate<T> predicate, List<T> result)
{
if (result == null) return;
if (Bound.Intersects(sphere))
{
if (m_childs.Length == 0)
{
var items = m_items;
for (int index = 0; index < items.Length; index++)
{
var item = items[index];
if (item == null)
break;
if (sphere.Contains(item.Position) && (predicate?.Invoke(item) ?? true))
result.Add(item);
}
}
else
{
for (int index = 0; index < m_childs.Length; index++)
m_childs[index].Select(sphere, predicate, result);
}
}
Parent?.Select(sphere, predicate, result);
}
public void ForEach(BoundingSphere sphere, Predicate<T> predicate, Action<T> action)
{
if (action == null) return;
if (Bound.Intersects(sphere))
{
if (m_childs.Length == 0)
{
var items = m_items;
for (int index = 0; index < items.Length; index++)
{
var item = items[index];
if (item == null)
break;
if (sphere.Contains(item.Position) && (predicate?.Invoke(item) ?? true))
action(item);
}
}
else
{
for (int index = 0; index < m_childs.Length; index++)
m_childs[index].ForEach(sphere, predicate, action);
}
}
Parent?.ForEach(sphere, predicate, action);
}