Skip to content

Commit 47cb766

Browse files
committed
doc
1 parent ee99e32 commit 47cb766

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/edge_table.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,14 +376,17 @@ impl EdgeTable {
376376
crate::table_column::OpaqueTableColumn(self.parent_slice())
377377
}
378378

379+
/// Table column with ergonomic indexing.
379380
pub fn child_column(&self) -> impl crate::TableColumn<EdgeId, NodeId> + '_ {
380381
crate::table_column::OpaqueTableColumn(self.child_slice())
381382
}
382383

384+
/// Table column with ergonomic indexing.
383385
pub fn left_column(&self) -> impl crate::TableColumn<EdgeId, Position> + '_ {
384386
crate::table_column::OpaqueTableColumn(self.left_slice())
385387
}
386388

389+
/// Table column with ergonomic indexing.
387390
pub fn right_column(&self) -> impl crate::TableColumn<EdgeId, Position> + '_ {
388391
crate::table_column::OpaqueTableColumn(self.right_slice())
389392
}

src/traits.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,23 @@ impl private::NewTypeMarker for crate::ProvenanceId {}
144144
/// # Notes
145145
///
146146
/// * This trait is sealed.
147+
///
148+
/// # For C programmers
149+
///
150+
/// The `C` programming language allows implicit casts between
151+
/// integer types.
152+
/// This implicit behavior allows one to index a table column
153+
/// using a row id type ([`crate::bindings::tsk_id_t`]) because
154+
/// the compiler will cast it to `size_t`.
155+
///
156+
/// `rust` does not allow implicit casts, which makes working
157+
/// with table columns as slices awkward.
158+
/// One has to manually cast the id type and the resulting code isn't
159+
/// nice to read.
160+
///
161+
/// This trait solves that problem by requiring that [`std::ops::Index`]
162+
/// by implemented for types that one would like to use as indexes
163+
/// in the `tskit` world.
147164
pub trait TableColumn<I, T>:
148165
std::ops::Index<I, Output = T>
149166
+ std::ops::Index<usize, Output = T>

0 commit comments

Comments
 (0)