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))ifrowis valid and decoding succeeded.Some(Err(_))ifrowis not valid and decoding failed.Noneifrowis not valid.
§Errors
TskitError::MetadataErrorif 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>
Trait Implementations§
Source§impl Default for OwningPopulationTable
impl Default for OwningPopulationTable
Source§impl Deref for OwningPopulationTable
impl Deref for OwningPopulationTable
Auto Trait Implementations§
impl Freeze for OwningPopulationTable
impl RefUnwindSafe for OwningPopulationTable
impl !Send for OwningPopulationTable
impl !Sync for OwningPopulationTable
impl Unpin for OwningPopulationTable
impl UnwindSafe for OwningPopulationTable
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more