feat(core): add Row::column, Row::try_column (from 0.5)

This commit is contained in:
Ryan Leckey 2021-02-22 21:32:52 -08:00
parent d8e4030cb8
commit 21f3a83c5f
No known key found for this signature in database
GPG Key ID: F8AA68C235AB08C9
2 changed files with 27 additions and 0 deletions

View File

@ -19,6 +19,15 @@ pub trait Row: 'static + Send + Sync {
/// Returns a reference to the columns in the row.
fn columns(&self) -> &[<Self::Database as Database>::Column];
/// Returns the column at the index, if available.
fn column<I: ColumnIndex<Self>>(&self, index: I) -> &<Self::Database as Database>::Column;
/// Returns the column at the index, if available.
fn try_column<I: ColumnIndex<Self>>(
&self,
index: I,
) -> crate::Result<&<Self::Database as Database>::Column>;
/// Returns the column name, given the index of the column.
fn column_name_of(&self, index: usize) -> &str;

View File

@ -41,6 +41,16 @@ impl MySqlRow {
&self.columns
}
/// Returns the column at the index, if available.
fn column<I: ColumnIndex<Self>>(&self, index: I) -> &MySqlColumn {
self.try_column(index).unwrap()
}
/// Returns the column at the index, if available.
fn try_column<I: ColumnIndex<Self>>(&self, index: I) -> Result<&MySqlColumn> {
Ok(&self.columns[index.get(self)?])
}
/// Returns the column name, given the index of the column.
#[must_use]
pub fn column_name_of(&self, index: usize) -> &str {
@ -112,6 +122,14 @@ impl Row for MySqlRow {
self.columns()
}
fn column<I: ColumnIndex<Self>>(&self, index: I) -> &MySqlColumn {
self.column(index)
}
fn try_column<I: ColumnIndex<Self>>(&self, index: I) -> Result<&MySqlColumn> {
self.try_column(index)
}
fn column_name_of(&self, index: usize) -> &str {
self.column_name_of(index)
}