Struct 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§

Methods from Deref<Target = PopulationTable>§

Source

pub fn num_rows(&self) -> SizeType

Return the number of rows.

Source

pub fn metadata<T: PopulationMetadata>( &self, row: 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 not valid and decoding failed.
  • None if row is not valid.
§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 = PopulationTableRow> + '_

Return an iterator over rows of the table. The value of the iterator is PopulationTableRow.

Source

pub fn lending_iter(&self) -> PopulationTableRowView<'_>

Source

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

Return row r of the table.

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

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) if r is valid
  • None otherwise

Trait Implementations§

Source§

impl Default for OwningPopulationTable

Source§

fn default() -> Self

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

impl Deref for OwningPopulationTable

Source§

type Target = PopulationTable

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for OwningPopulationTable

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

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> Free for T

Source§

default unsafe fn free(ptr_ref: NonNull<T>)

Drops the content pointed by this pointer and frees it. 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.