From 947a51775e7f72f5d334df8f94bef8fe7be530e1 Mon Sep 17 00:00:00 2001 From: Bittrance Date: Thu, 17 Aug 2023 12:10:35 +0200 Subject: [PATCH] Allow iterating over the cells in a row. (#303) --- src/row.rs | 10 ++++++++++ src/tds/codec/token/token_row.rs | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/src/row.rs b/src/row.rs index 34c591d0..59edfd8d 100644 --- a/src/row.rs +++ b/src/row.rs @@ -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 @@ -291,6 +296,11 @@ impl Row { &self.columns } + /// Return an iterator over row column-value pairs. + pub fn cells(&self) -> impl Iterator)> { + 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 { diff --git a/src/tds/codec/token/token_row.rs b/src/tds/codec/token/token_row.rs index d724e817..b1ff16b6 100644 --- a/src/tds/codec/token/token_row.rs +++ b/src/tds/codec/token/token_row.rs @@ -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()