Struct tskit::OwnedSiteTable

source ·
pub struct OwnedSiteTable { /* private fields */ }
Expand description

A standalone site table that owns its data.

Examples

use tskit::OwnedSiteTable;

let mut sites = OwnedSiteTable::default();
let rowid = sites.add_row(1., None).unwrap();
assert_eq!(rowid, 0);
assert_eq!(sites.num_rows(), 1);

An example with metadata. This requires the cargo feature "derive" for tskit.

use tskit::OwnedSiteTable;

#[derive(serde::Serialize,
         serde::Deserialize,
         tskit::metadata::SiteMetadata)]
#[serializer("serde_json")]
struct SiteMetadata {
    value: i32,
}

let metadata = SiteMetadata{value: 42};

let mut sites = OwnedSiteTable::default();

let rowid = sites.add_row_with_metadata(0., None, &metadata).unwrap();
assert_eq!(rowid, 0);

match sites.metadata::<SiteMetadata>(rowid) {
    // rowid is in range, decoding succeeded
    Some(Ok(decoded)) => assert_eq!(decoded.value, 42),
    // rowid is in range, decoding failed
    Some(Err(e)) => panic!("error decoding metadata: {:?}", e),
    None => panic!("row id out of range")
}

Implementations

Clear the table.

Methods from Deref<Target = SiteTable>

Return the number of rows

Return the position value from row row of the table.

Returns
  • Some(position) if row is valid.
  • None otherwise.

Get the ancestral_state value from row row of the table.

Returns
  • Some(ancestral state) if row is valid.
  • None otherwise.

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.

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

Return row r of the table.

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

Return a view of row r of the table.

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

Get the position column as a slice

Get the position column as a slice

Trait Implementations

Returns the “default value” for a type. Read more
The resulting type after dereferencing.
Dereferences the value.
Mutably dereferences the value.
Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Drops the content pointed by this pointer and frees it. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.