Struct tskit::OwnedMigrationTable
source · [−]pub struct OwnedMigrationTable { /* private fields */ }
Expand description
A standalone migration table that owns its data.
Examples
use tskit::OwnedMigrationTable;
let mut migrations = OwnedMigrationTable::default();
let rowid = migrations.add_row((0., 1.), 1, (0, 1), 10.3).unwrap();
assert_eq!(rowid, 0);
assert_eq!(migrations.num_rows(), 1);
An example with metadata.
This requires the cargo feature "derive"
for tskit
.
use tskit::OwnedMigrationTable;
#[derive(serde::Serialize,
serde::Deserialize,
tskit::metadata::MigrationMetadata)]
#[serializer("serde_json")]
struct MigrationMetadata {
value: i32,
}
let metadata = MigrationMetadata{value: 42};
let mut migrations = OwnedMigrationTable::default();
let rowid = migrations.add_row_with_metadata((0., 1.), 1, (0, 1), 10.3, &metadata).unwrap();
assert_eq!(rowid, 0);
if let Some(decoded) = migrations.metadata::<MigrationMetadata>(rowid).unwrap() {
assert_eq!(decoded.value, 42);
} else {
panic!("hmm...we expected some metadata!");
}
Implementations
sourceimpl OwnedMigrationTable
impl OwnedMigrationTable
sourcepub fn clear(&mut self) -> TskReturnValue
pub fn clear(&mut self) -> TskReturnValue
Clear the table.
sourceimpl OwnedMigrationTable
impl OwnedMigrationTable
pub fn as_ptr(&self) -> *const tsk_migration_table_t
pub fn as_mut_ptr(&mut self) -> *mut tsk_migration_table_t
sourceimpl OwnedMigrationTable
impl OwnedMigrationTable
pub fn add_row<LEFT, RIGHT, N, SOURCE, DEST, T>(
&mut self,
span: (LEFT, RIGHT),
node: N,
source_dest: (SOURCE, DEST),
time: T
) -> Result<MigrationId, TskitError>where
LEFT: Into<Position>,
RIGHT: Into<Position>,
N: Into<NodeId>,
SOURCE: Into<PopulationId>,
DEST: Into<PopulationId>,
T: Into<Time>,
pub fn add_row_with_metadata<LEFT, RIGHT, N, SOURCE, DEST, T, M>(
&mut self,
span: (LEFT, RIGHT),
node: N,
source_dest: (SOURCE, DEST),
time: T,
metadata: &M
) -> Result<MigrationId, TskitError>where
LEFT: Into<Position>,
RIGHT: Into<Position>,
N: Into<NodeId>,
SOURCE: Into<PopulationId>,
DEST: Into<PopulationId>,
T: Into<Time>,
M: MigrationMetadata,
Methods from Deref<Target = MigrationTable<'static>>
sourcepub fn left<M: Into<MigrationId> + Copy>(
&'a self,
row: M
) -> Result<Position, TskitError>
pub fn left<M: Into<MigrationId> + Copy>(
&'a self,
row: M
) -> Result<Position, TskitError>
sourcepub fn right<M: Into<MigrationId> + Copy>(
&'a self,
row: M
) -> Result<Position, TskitError>
pub fn right<M: Into<MigrationId> + Copy>(
&'a self,
row: M
) -> Result<Position, TskitError>
sourcepub fn node<M: Into<MigrationId> + Copy>(
&'a self,
row: M
) -> Result<NodeId, TskitError>
pub fn node<M: Into<MigrationId> + Copy>(
&'a self,
row: M
) -> Result<NodeId, TskitError>
sourcepub fn source<M: Into<MigrationId> + Copy>(
&'a self,
row: M
) -> Result<PopulationId, TskitError>
pub fn source<M: Into<MigrationId> + Copy>(
&'a self,
row: M
) -> Result<PopulationId, TskitError>
sourcepub fn dest<M: Into<MigrationId> + Copy>(
&'a self,
row: M
) -> Result<PopulationId, TskitError>
pub fn dest<M: Into<MigrationId> + Copy>(
&'a self,
row: M
) -> Result<PopulationId, TskitError>
Return the destination population for a given row.
Errors
TskitError::IndexError
ifrow
is out of range.
sourcepub fn time<M: Into<MigrationId> + Copy>(
&'a self,
row: M
) -> Result<Time, TskitError>
pub fn time<M: Into<MigrationId> + Copy>(
&'a self,
row: M
) -> Result<Time, TskitError>
Return the time of the migration event for a given row.
Errors
TskitError::IndexError
ifrow
is out of range.
sourcepub fn metadata<T: MetadataRoundtrip>(
&'a self,
row: MigrationId
) -> Result<Option<T>, TskitError>
pub fn metadata<T: MetadataRoundtrip>(
&'a self,
row: MigrationId
) -> Result<Option<T>, TskitError>
sourcepub fn iter(&self) -> impl Iterator<Item = MigrationTableRow> + '_
pub fn iter(&self) -> impl Iterator<Item = MigrationTableRow> + '_
Return an iterator over rows of the table.
The value of the iterator is MigrationTableRow
.
sourcepub fn row<M: Into<MigrationId> + Copy>(
&self,
r: M
) -> Result<MigrationTableRow, TskitError>
pub fn row<M: Into<MigrationId> + Copy>(
&self,
r: M
) -> Result<MigrationTableRow, 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 OwnedMigrationTable
impl Default for OwnedMigrationTable
sourceimpl Deref for OwnedMigrationTable
impl Deref for OwnedMigrationTable
type Target = MigrationTable<'static>
type Target = MigrationTable<'static>
The resulting type after dereferencing.
Auto Trait Implementations
impl RefUnwindSafe for OwnedMigrationTable
impl !Send for OwnedMigrationTable
impl !Sync for OwnedMigrationTable
impl Unpin for OwnedMigrationTable
impl UnwindSafe for OwnedMigrationTable
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