Struct tskit::OwnedPopulationTable
source · pub struct OwnedPopulationTable { /* private fields */ }
Expand description
A standalone population table that owns its data.
Examples
use tskit::OwnedPopulationTable;
let mut populations = OwnedPopulationTable::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::OwnedPopulationTable;
#[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 = OwnedPopulationTable::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
sourceimpl OwnedPopulationTable
impl OwnedPopulationTable
sourcepub fn clear(&mut self) -> TskReturnValue
pub fn clear(&mut self) -> TskReturnValue
Clear the table.
sourceimpl OwnedPopulationTable
impl OwnedPopulationTable
pub fn as_ptr(&self) -> *const tsk_population_table_t
pub fn as_mut_ptr(&mut self) -> *mut tsk_population_table_t
sourceimpl OwnedPopulationTable
impl OwnedPopulationTable
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
.
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
sourceimpl Default for OwnedPopulationTable
impl Default for OwnedPopulationTable
sourceimpl Deref for OwnedPopulationTable
impl Deref for OwnedPopulationTable
type Target = PopulationTable
type Target = PopulationTable
The resulting type after dereferencing.
sourceimpl DerefMut for OwnedPopulationTable
impl DerefMut for OwnedPopulationTable
Auto Trait Implementations
impl RefUnwindSafe for OwnedPopulationTable
impl !Send for OwnedPopulationTable
impl !Sync for OwnedPopulationTable
impl Unpin for OwnedPopulationTable
impl UnwindSafe for OwnedPopulationTable
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