Skip to content

Commit

Permalink
Allow iterating over the cells in a row. (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
bittrance committed Aug 17, 2023
1 parent 98943b2 commit 947a517
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ pub struct Column {
}

impl Column {
/// Construct a new Column.
pub fn new(name: String, column_type: ColumnType) -> Self {
Self { name, column_type }
}

/// The name of the column.
pub fn name(&self) -> &str {
&self.name
Expand Down Expand Up @@ -291,6 +296,11 @@ impl Row {
&self.columns
}

/// Return an iterator over row column-value pairs.
pub fn cells(&self) -> impl Iterator<Item = (&Column, &ColumnData<'static>)> {
self.columns().iter().zip(self.data.iter())
}

/// The result set number, starting from zero and increasing if the stream
/// has results from more than one query.
pub fn result_index(&self) -> usize {
Expand Down
5 changes: 5 additions & 0 deletions src/tds/codec/token/token_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ impl<'a> TokenRow<'a> {
self.data.len()
}

/// Returns an iterator over column values.
pub fn iter(&self) -> std::slice::Iter<'_, ColumnData<'a>> {
self.data.iter()
}

/// True if row has no columns.
pub fn is_empty(&self) -> bool {
self.data.is_empty()
Expand Down

0 comments on commit 947a517

Please sign in to comment.