Skip to content

Commit 5dc109c

Browse files
committed
provide more impls
1 parent 47cb766 commit 5dc109c

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

src/traits.rs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -170,20 +170,27 @@ pub trait TableColumn<I, T>:
170170
/// Get the underlying slice
171171
fn as_slice(&self) -> &[T];
172172

173-
/// The "standard" get function
174-
fn get(&self, at: usize) -> Option<&T>;
175-
176173
/// Get with a table row identifier such as [`crate::NodeId`]
177174
fn get_with_id(&self, at: I) -> Option<&T>;
178175

176+
/// The "standard" get function
177+
fn get(&self, at: usize) -> Option<&T> {
178+
self.as_slice().get(at)
179+
}
180+
179181
/// Get with [`crate::SizeType`]
180-
fn get_with_size_type(&self, at: crate::SizeType) -> Option<&T>;
182+
fn get_with_size_type(&self, at: crate::SizeType) -> Option<&T> {
183+
self.as_slice().get(usize::try_from(at).ok()?)
184+
}
181185

182186
/// Iterator over the data.
183187
fn iter<'a, 'b>(&'a self) -> impl Iterator<Item = &'b T>
184188
where
185189
'a: 'b,
186-
T: 'b;
190+
T: 'b,
191+
{
192+
self.as_slice().iter()
193+
}
187194

188195
/// Column length
189196
fn len(&self) -> usize {
@@ -216,23 +223,7 @@ where
216223
self.0
217224
}
218225

219-
fn get(&self, at: usize) -> Option<&T> {
220-
self.0.get(at)
221-
}
222-
223226
fn get_with_id(&self, at: I) -> Option<&T> {
224227
self.0.get(at.try_into().ok()?)
225228
}
226-
227-
fn get_with_size_type(&self, at: crate::SizeType) -> Option<&T> {
228-
self.0.get(usize::try_from(at).ok()?)
229-
}
230-
231-
fn iter<'a, 'b>(&'a self) -> impl Iterator<Item = &'b T>
232-
where
233-
'a: 'b,
234-
T: 'b,
235-
{
236-
self.0.iter()
237-
}
238229
}

0 commit comments

Comments
 (0)