Repository: bevyengine/bevy
File: crates/bevy_reflect/src/structs.rs (Rust)

Code before:
        let mut extract = self.field_names.extract_if(0..self.field_names.len(), |n| {
            let mut result = false;
            if i == index {
                self.field_indices
                    .remove(n)
                    .expect("Invalid name for `field_indices.remove(name)`");
                result = true;
            } else if i > index {
                *self
                    .field_indices
                    .get_mut(n)
                    .expect("Invalid name for `field_indices.get_mut(name)`") -= 1;
            }
            i += 1;
            result
        });

        let name = extract
            .nth(0)
            .expect("Invalid index for `extract.nth(index)`");
        extract.for_each(drop); // Fully evaluate the rest of the iterator, so we don't short-circuit the extract.

        Some((name, self.fields.remove(index)))
    }

    /// Removes a field with the predicate `f`, that short-circuits.
    pub fn remove_with<F>(
        &mut self,
        mut f: F,
    ) -> Option<(Cow<'static, str>, Box<dyn PartialReflect>)>
    where
        F: FnMut((&str, &dyn PartialReflect)) -> bool,
    {
        if let Some(index) = self
            .field_names
            .iter()
            .zip(self.fields.iter())
            .position(|(name, field)| f((name.as_ref(), field.as_ref())))
        {
            self.remove_at(index)
        } else {
            None
        }
    }

    /// Removes a field by `name`.
    pub fn remove_by_name(
        &mut self,
        name: &str,
    ) -> Option<(Cow<'static, str>, Box<dyn PartialReflect>)> {
        if let Some(index) = self.index_of_name(name) {

Review comment (suggestion):
Nit: maybe rather than "short-circuits" we say something more along the lines of this?
```suggestion
    /// Removes the first field that satisfies the given predicate, `f`.
```
Just a bit clearer for those who aren't familiar with that terminology.

Code after:
    where
        F: FnMut((&str, &dyn PartialReflect)) -> bool,
    {
        if let Some(index) = self
            .field_names
            .iter()
            .zip(self.fields.iter())
            .position(|(name, field)| f((name.as_ref(), field.as_ref())))
        {
            self.remove_at(index)
        } else {
            None
        }
    }

    /// Removes a field by `name`.
    pub fn remove_by_name(
        &mut self,
        name: &str,
    ) -> Option<(Cow<'static, str>, Box<dyn PartialReflect>)> {
        if let Some(index) = self.index_of(name) {
            self.remove_at(index)
        } else {
            None
        }
    }

    /// Gets the index of the field with the given name.
    pub fn index_of(&self, name: &str) -> Option<usize> {
        self.field_indices.get(name).copied()
    }
}

impl Struct for DynamicStruct {
    #[inline]
    fn field(&self, name: &str) -> Option<&dyn PartialReflect> {
        self.field_indices
            .get(name)
            .map(|index| &*self.fields[*index])
    }

    #[inline]
    fn field_mut(&mut self, name: &str) -> Option<&mut dyn PartialReflect> {
        if let Some(index) = self.field_indices.get(name) {
            Some(&mut *self.fields[*index])
        } else {
            None
        }
    }

    #[inline]