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
sourceimpl OwnedSiteTable
impl OwnedSiteTable
sourcepub fn clear(&mut self) -> TskReturnValue
pub fn clear(&mut self) -> TskReturnValue
Clear the table.
sourceimpl OwnedSiteTable
impl OwnedSiteTable
pub fn as_ptr(&self) -> *const tsk_site_table_t
pub fn as_mut_ptr(&mut self) -> *mut tsk_site_table_t
sourceimpl OwnedSiteTable
impl OwnedSiteTable
pub fn add_row<P>(
&mut self,
position: P,
ancestral_state: Option<&[u8]>
) -> Result<SiteId, TskitError>where
P: Into<Position>,
pub fn add_row_with_metadata<P, M>(
&mut self,
position: P,
ancestral_state: Option<&[u8]>,
metadata: &M
) -> Result<SiteId, TskitError>where
P: Into<Position>,
M: SiteMetadata,
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
.
Trait Implementations
sourceimpl Default for OwnedSiteTable
impl Default for OwnedSiteTable
sourceimpl Deref for OwnedSiteTable
impl Deref for OwnedSiteTable
sourceimpl DerefMut for OwnedSiteTable
impl DerefMut for OwnedSiteTable
Auto Trait Implementations
impl RefUnwindSafe for OwnedSiteTable
impl !Send for OwnedSiteTable
impl !Sync for OwnedSiteTable
impl Unpin for OwnedSiteTable
impl UnwindSafe for OwnedSiteTable
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more