Struct tskit::OwnedEdgeTable
source · [−]pub struct OwnedEdgeTable { /* private fields */ }
Expand description
A standalone edge table that owns its data.
Examples
use tskit::OwnedEdgeTable;
let mut edges = OwnedEdgeTable::default();
let rowid = edges.add_row(1., 2., 0, 1).unwrap();
assert_eq!(rowid, 0);
assert_eq!(edges.num_rows(), 1);
edges.clear().unwrap();
assert_eq!(edges.num_rows(), 0);
An example with metadata.
This requires the cargo feature "derive"
for tskit
.
use tskit::OwnedEdgeTable;
#[derive(serde::Serialize,
serde::Deserialize,
tskit::metadata::EdgeMetadata)]
#[serializer("serde_json")]
struct EdgeMetadata {
value: i32,
}
let metadata = EdgeMetadata{value: 42};
let mut edges = OwnedEdgeTable::default();
let rowid = edges.add_row_with_metadata(0., 1., 5, 10, &metadata).unwrap();
assert_eq!(rowid, 0);
if let Some(decoded) = edges.metadata::<EdgeMetadata>(rowid).unwrap() {
assert_eq!(decoded.value, 42);
} else {
panic!("hmm...we expected some metadata!");
}
Implementations
sourceimpl OwnedEdgeTable
impl OwnedEdgeTable
sourcepub fn clear(&mut self) -> TskReturnValue
pub fn clear(&mut self) -> TskReturnValue
Clear the table.
sourceimpl OwnedEdgeTable
impl OwnedEdgeTable
pub fn as_ptr(&self) -> *const tsk_edge_table_t
pub fn as_mut_ptr(&mut self) -> *mut tsk_edge_table_t
sourceimpl OwnedEdgeTable
impl OwnedEdgeTable
pub fn add_row<L, R, P, C>(
&mut self,
left: L,
right: R,
parent: P,
child: C
) -> Result<EdgeId, TskitError>where
L: Into<Position>,
R: Into<Position>,
P: Into<NodeId>,
C: Into<NodeId>,
pub fn add_row_with_metadata<L, R, P, C, M>(
&mut self,
left: L,
right: R,
parent: P,
child: C,
metadata: &M
) -> Result<EdgeId, TskitError>where
L: Into<Position>,
R: Into<Position>,
P: Into<NodeId>,
C: Into<NodeId>,
M: EdgeMetadata,
Methods from Deref<Target = EdgeTable<'static>>
sourcepub fn parent<E: Into<EdgeId> + Copy>(
&'a self,
row: E
) -> Result<NodeId, TskitError>
pub fn parent<E: Into<EdgeId> + Copy>(
&'a self,
row: E
) -> Result<NodeId, TskitError>
Return the parent
value from row row
of the table.
Errors
Will return IndexError
if row
is out of range.
sourcepub fn child<E: Into<EdgeId> + Copy>(
&'a self,
row: E
) -> Result<NodeId, TskitError>
pub fn child<E: Into<EdgeId> + Copy>(
&'a self,
row: E
) -> Result<NodeId, TskitError>
Return the child
value from row row
of the table.
Errors
Will return IndexError
if row
is out of range.
sourcepub fn left<E: Into<EdgeId> + Copy>(
&'a self,
row: E
) -> Result<Position, TskitError>
pub fn left<E: Into<EdgeId> + Copy>(
&'a self,
row: E
) -> Result<Position, TskitError>
Return the left
value from row row
of the table.
Errors
Will return IndexError
if row
is out of range.
sourcepub fn right<E: Into<EdgeId> + Copy>(
&'a self,
row: E
) -> Result<Position, TskitError>
pub fn right<E: Into<EdgeId> + Copy>(
&'a self,
row: E
) -> Result<Position, TskitError>
Return the right
value from row row
of the table.
Errors
Will return IndexError
if row
is out of range.
pub fn metadata<T: MetadataRoundtrip>(
&'a self,
row: EdgeId
) -> Result<Option<T>, TskitError>
sourcepub fn iter(&self) -> impl Iterator<Item = EdgeTableRow> + '_
pub fn iter(&self) -> impl Iterator<Item = EdgeTableRow> + '_
Return an iterator over rows of the table.
The value of the iterator is EdgeTableRow
.
sourcepub fn row<E: Into<EdgeId> + Copy>(
&self,
r: E
) -> Result<EdgeTableRow, TskitError>
pub fn row<E: Into<EdgeId> + Copy>(
&self,
r: E
) -> Result<EdgeTableRow, TskitError>
Return row r
of the table.
Parameters
r
: the row id.
Errors
TskitError::IndexError
if r
is out of range.
Trait Implementations
sourceimpl Default for OwnedEdgeTable
impl Default for OwnedEdgeTable
sourceimpl Deref for OwnedEdgeTable
impl Deref for OwnedEdgeTable
Auto Trait Implementations
impl RefUnwindSafe for OwnedEdgeTable
impl !Send for OwnedEdgeTable
impl !Sync for OwnedEdgeTable
impl Unpin for OwnedEdgeTable
impl UnwindSafe for OwnedEdgeTable
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more