Skip to main content

PopulationTable

Struct PopulationTable 

Source
pub struct PopulationTable { /* private fields */ }
Expand description

A population table

§Examples

use tskit::PopulationTable;

let mut populations = PopulationTable::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::PopulationTable;

#[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 = PopulationTable::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 PopulationTable

Source

pub fn num_rows(&self) -> SizeType

Return the number of rows.

Source

pub fn metadata<T: PopulationMetadata>( &self, row: impl Into<PopulationId>, ) -> Option<Result<T, TskitError>>

Retrieve decoded metadata for a row.

§Returns
  • Some(Ok(T)) if row is valid and decoding succeeded.
  • Some(Err(_)) if row is valid and decoding failed.
  • None if row is not valid or the row has no metadata.
§Errors
§Examples.

The big-picture semantics are the same for all table types. See crate::IndividualTable::metadata for examples.

Source

pub fn iter(&self) -> impl Iterator<Item = Population<'_>>

Return an iterator over rows of the table. The value of the iterator is crate::Population.

Source

pub fn row<P: Into<PopulationId> + Copy>(&self, r: P) -> Option<Population<'_>>

§Parameters
  • r: the row id.
§Returns
  • Some(row) if r is valid
  • None otherwise
Source

pub fn add_row(&mut self) -> Result<PopulationId, TskitError>

Source

pub fn add_row_with_metadata<M: PopulationMetadata>( &mut self, metadata: &M, ) -> Result<PopulationId, TskitError>

Source

pub fn clear(&mut self) -> Result<i32, TskitError>

Clear all data from the table

Trait Implementations§

Source§

impl Debug for PopulationTable

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PopulationTable

Source§

fn default() -> PopulationTable

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.