pub struct SiteTable { /* private fields */ }Expand description
A site table.
§Examples
use tskit::SiteTable;
let mut sites = SiteTable::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::SiteTable;
#[derive(serde::Serialize,
serde::Deserialize,
tskit::metadata::SiteMetadata)]
#[serializer("serde_json")]
struct SiteMetadata {
value: i32,
}
let metadata = SiteMetadata{value: 42};
let mut sites = SiteTable::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§
Source§impl SiteTable
impl SiteTable
Sourcepub fn position<S: Into<SiteId> + Copy>(&self, row: S) -> Option<Position>
pub fn position<S: Into<SiteId> + Copy>(&self, row: S) -> Option<Position>
Return the position value from row row of the table.
§Returns
Some(position)ifrowis valid.Noneotherwise.
Sourcepub fn ancestral_state<S: Into<SiteId>>(&self, row: S) -> Option<&[u8]>
pub fn ancestral_state<S: Into<SiteId>>(&self, row: S) -> Option<&[u8]>
Get the ancestral_state value from row row of the table.
§Returns
Some(ancestral state)ifrowis valid.Noneotherwise.
Sourcepub fn metadata<T: SiteMetadata>(
&self,
row: impl Into<SiteId>,
) -> Option<Result<T, TskitError>>
pub fn metadata<T: SiteMetadata>( &self, row: impl Into<SiteId>, ) -> Option<Result<T, TskitError>>
Retrieve decoded metadata for a row.
§Returns
Some(Ok(T))ifrowis valid and decoding succeeded.Some(Err(_))ifrowis valid and decoding failed.Noneifrowis not valid or the row has no metadata.
§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 = SiteTableRow> + '_
pub fn iter(&self) -> impl Iterator<Item = SiteTableRow> + '_
Return an iterator over rows of the table.
The value of the iterator is SiteTableRow.
pub fn lending_iter(&self) -> SiteTableRowView<'_>
Sourcepub fn position_slice(&self) -> &[Position]
pub fn position_slice(&self) -> &[Position]
Get the position column as a slice
Sourcepub fn position_slice_raw(&self) -> &[f64]
pub fn position_slice_raw(&self) -> &[f64]
Get the position column as a slice
pub fn position_column(&self) -> impl TableColumn<SiteId, Position> + '_
Sourcepub fn clear(&mut self) -> Result<i32, TskitError>
pub fn clear(&mut self) -> Result<i32, TskitError>
Clear all data from the table
pub fn add_row<P: Into<Position>>( &mut self, position: P, ancestral_state: Option<&[u8]>, ) -> Result<SiteId, TskitError>
pub fn add_row_with_metadata<P: Into<Position>, M: SiteMetadata>( &mut self, position: P, ancestral_state: Option<&[u8]>, metadata: &M, ) -> Result<SiteId, TskitError>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SiteTable
impl RefUnwindSafe for SiteTable
impl Send for SiteTable
impl Sync for SiteTable
impl Unpin for SiteTable
impl UnsafeUnpin for SiteTable
impl UnwindSafe for SiteTable
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