pub struct OwningSiteTable { /* private fields */ }
Expand description
A standalone site table that owns its data.
§Examples
use tskit::OwningSiteTable;
let mut sites = OwningSiteTable::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::OwningSiteTable;
#[derive(serde::Serialize,
serde::Deserialize,
tskit::metadata::SiteMetadata)]
#[serializer("serde_json")]
struct SiteMetadata {
value: i32,
}
let metadata = SiteMetadata{value: 42};
let mut sites = OwningSiteTable::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 OwningSiteTable
impl OwningSiteTable
Sourcepub fn clear(&mut self) -> TskReturnValue
pub fn clear(&mut self) -> TskReturnValue
Clear the table.
Source§impl OwningSiteTable
impl OwningSiteTable
pub fn as_ptr(&self) -> *const tsk_site_table_t
pub fn as_mut_ptr(&mut self) -> *mut tsk_site_table_t
Source§impl OwningSiteTable
impl OwningSiteTable
pub fn add_row<P>( &mut self, position: P, ancestral_state: Option<&[u8]>, ) -> Result<SiteId, TskitError>
pub fn add_row_with_metadata<P, M>( &mut self, position: P, ancestral_state: Option<&[u8]>, metadata: &M, ) -> Result<SiteId, TskitError>
Methods from Deref<Target = 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)
ifrow
is valid.None
otherwise.
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)
ifrow
is valid.None
otherwise.
Sourcepub fn metadata<T: SiteMetadata>(
&self,
row: SiteId,
) -> Option<Result<T, TskitError>>
pub fn metadata<T: SiteMetadata>( &self, row: SiteId, ) -> 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 = 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
Trait Implementations§
Source§impl Default for OwningSiteTable
impl Default for OwningSiteTable
Source§impl Deref for OwningSiteTable
impl Deref for OwningSiteTable
Auto Trait Implementations§
impl Freeze for OwningSiteTable
impl RefUnwindSafe for OwningSiteTable
impl !Send for OwningSiteTable
impl !Sync for OwningSiteTable
impl Unpin for OwningSiteTable
impl UnwindSafe for OwningSiteTable
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