Struct tskit::OwningPopulationTable
source · pub struct OwningPopulationTable { /* private fields */ }
Expand description
A standalone population table that owns its data.
Examples
use tskit::OwningPopulationTable;
let mut populations = OwningPopulationTable::default();
let rowid = populations.add_row().unwrap();
assert_eq!(rowid, 0);
assert_eq!(populations.num_rows(), 1);
An example with metadata.
This requires the cargo feature "derive"
for tskit
.
use tskit::OwningPopulationTable;
#[derive(serde::Serialize,
serde::Deserialize,
tskit::metadata::PopulationMetadata)]
#[serializer("serde_json")]
struct PopulationMetadata {
name: String,
}
let metadata = PopulationMetadata{name: "YRB".to_string()};
let mut populations = OwningPopulationTable::default();
let rowid = populations.add_row_with_metadata(&metadata).unwrap();
assert_eq!(rowid, 0);
match populations.metadata::<PopulationMetadata>(rowid) {
// rowid is in range, decoding succeeded
Some(Ok(decoded)) => assert_eq!(&decoded.name, "YRB"),
// rowid is in range, decoding failed
Some(Err(e)) => panic!("error decoding metadata: {:?}", e),
None => panic!("row id out of range")
}
Implementations§
source§impl OwningPopulationTable
impl OwningPopulationTable
sourcepub fn clear(&mut self) -> TskReturnValue
pub fn clear(&mut self) -> TskReturnValue
Clear the table.
source§impl OwningPopulationTable
impl OwningPopulationTable
pub fn as_ptr(&self) -> *const tsk_population_table_t
pub fn as_mut_ptr(&mut self) -> *mut tsk_population_table_t
source§impl OwningPopulationTable
impl OwningPopulationTable
pub fn add_row(&mut self) -> Result<PopulationId, TskitError>
pub fn add_row_with_metadata<M>( &mut self, metadata: &M ) -> Result<PopulationId, TskitError>where M: PopulationMetadata,
Methods from Deref<Target = PopulationTable>§
sourcepub fn metadata<T: PopulationMetadata>(
&self,
row: PopulationId
) -> Option<Result<T, TskitError>>
pub fn metadata<T: PopulationMetadata>( &self, row: PopulationId ) -> Option<Result<T, TskitError>>
Retrieve decoded metadata for a row
.
Returns
Some(Ok(T))
ifrow
is valid and decoding succeeded.Some(Err(_))
ifrow
is not valid and decoding failed.None
ifrow
is not valid.
Errors
TskitError::MetadataError
if decoding fails.
Examples.
The big-picture semantics are the same for all table types.
See crate::IndividualTable::metadata
for examples.
sourcepub fn iter(&self) -> impl Iterator<Item = PopulationTableRow> + '_
pub fn iter(&self) -> impl Iterator<Item = PopulationTableRow> + '_
Return an iterator over rows of the table.
The value of the iterator is PopulationTableRow
.
pub fn lending_iter(&self) -> PopulationTableRowView<'_>
sourcepub fn row<P: Into<PopulationId> + Copy>(
&self,
r: P
) -> Option<PopulationTableRow>
pub fn row<P: Into<PopulationId> + Copy>( &self, r: P ) -> Option<PopulationTableRow>
sourcepub fn row_view<P: Into<PopulationId> + Copy>(
&self,
r: P
) -> Option<PopulationTableRowView<'_>>
pub fn row_view<P: Into<PopulationId> + Copy>( &self, r: P ) -> Option<PopulationTableRowView<'_>>
Return a view of row r
of the table.
Parameters
r
: the row id.
Returns
Some(row view)
ifr
is validNone
otherwise