Repository: diesel-rs/diesel
File: diesel_dynamic_schema/src/dynamic_value.rs (Rust)

Code before:
    }

    /// Get the mutable field value at the provided row index
    ///
    /// Returns `None` if the index is outside the bounds of the row
    pub fn get_mut(&mut self, index: usize) -> Option<&mut I> {
        self.values.get_mut(index)
    }

    /// Get the number of fields in the current row
    pub fn len(&self) -> usize {
        self.values.len()
    }

    /// Check if the current row is empty
    pub fn is_empty(&self) -> bool {
        self.values.is_empty()
    }

    /// Returns an iterator over the values of the row
    pub fn iter(&self) -> std::slice::Iter<'_, I> {
        self.values.iter()
    }

    /// Returns a mutable iterator over the values of the row
    pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, I> {
        self.values.iter_mut()
    }

    /// Create a new dynamic row from an existing database row
    ///
    /// This function is mostly useful for third party backends adding
    /// support for `diesel_dynamic_schema`
    pub fn from_row<'a, DB>(row: &impl Row<'a, DB>) -> deserialize::Result<Self>
    where
        DB: Backend,
        I: FromSql<Any, DB>,
    {
        let data = (0..row.field_count())
            .map(|i| {
                let field = Row::get(row, i).expect("We checked the field count above");

                I::from_nullable_sql(field.value())
            })
            .collect::<deserialize::Result<_>>()?;

        Ok(Self { values: data })
    }
}

impl<I> DynamicRow<NamedField<I>> {

Review comment (suggestion):
Rather use `impl Iterator<Item =&mut  I> + use<'_>` to make the type opaque

Code after:
    }

    /// Create a new dynamic row from an existing database row
    ///
    /// This function is mostly useful for third party backends adding
    /// support for `diesel_dynamic_schema`
    pub fn from_row<'a, DB>(row: &impl Row<'a, DB>) -> deserialize::Result<Self>
    where
        DB: Backend,
        I: FromSql<Any, DB>,
    {
        let data = (0..row.field_count())
            .map(|i| {
                let field = Row::get(row, i).expect("We checked the field count above");

                I::from_nullable_sql(field.value())
            })
            .collect::<deserialize::Result<_>>()?;

        Ok(Self { values: data })
    }
}

impl<I> DynamicRow<NamedField<I>> {
    /// Get the field value by the provided field name
    ///
    /// Returns `None` if the field with the specified name is not found.
    /// If there are multiple fields with the same name, the behaviour
    /// of this function is unspecified.
    pub fn get_by_name<S: AsRef<str>>(&self, name: S) -> Option<&I> {
        self.values
            .iter()
            .find(|f| f.name == name.as_ref())
            .map(|f| &f.value)
    }

    /// Get the mutable field value by the provided field name
    ///
    /// Returns `None` if the field with the specified name is not found.
    /// If there are multiple fields with the same name, the behaviour
    /// of this function is unspecified.
    pub fn get_mut_by_name<S: AsRef<str>>(&mut self, name: S) -> Option<&mut I> {
        self.values
            .iter_mut()
            .find(|f| f.name == name.as_ref())
            .map(|f| &mut f.value)
    }
}

impl<I> DynamicRow<NamedField<Option<I>>> {
    /// Create a new dynamic row instance with corresponding field information from the given