Get a value from the [MockRow]
(&self, index: I)
| 213 | impl MockRow { |
| 214 | /// Get a value from the [MockRow] |
| 215 | pub fn try_get<T, I: crate::ColIdx>(&self, index: I) -> Result<T, DbErr> |
| 216 | where |
| 217 | T: ValueType, |
| 218 | { |
| 219 | if let Some(index) = index.as_str() { |
| 220 | T::try_from( |
| 221 | self.values |
| 222 | .get(index) |
| 223 | .ok_or_else(|| query_err(format!("No column for ColIdx {index:?}")))? |
| 224 | .clone(), |
| 225 | ) |
| 226 | .map_err(type_err) |
| 227 | } else if let Some(index) = index.as_usize() { |
| 228 | let (_, value) = self |
| 229 | .values |
| 230 | .iter() |
| 231 | .nth(*index) |
| 232 | .ok_or_else(|| query_err(format!("Column at index {index} not found")))?; |
| 233 | T::try_from(value.clone()).map_err(type_err) |
| 234 | } else { |
| 235 | unreachable!("Missing ColIdx implementation for MockRow"); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | /// An iterator over the keys and values of a mock row |
| 240 | pub fn into_column_value_tuples(self) -> impl Iterator<Item = (String, Value)> { |