hts 0.1.18

Rust binding for htslib
Documentation
use super::VcfFile;
use crate::hts_ffi::{htslib_obj, BCF_DT_ID};
use crate::TypedValue;
use std::ffi::CStr;

pub struct PerSampleInfo<'a> {
    inner: &'a htslib_obj::BcfFmt,
    nsamples: u32,
    file: &'a VcfFile,
}

impl<'a> PerSampleInfo<'a> {
    pub(crate) fn from_inner(
        inner: &'a htslib_obj::BcfFmt,
        file: &'a VcfFile,
        nsamples: u32,
    ) -> Self {
        Self {
            inner,
            file,
            nsamples,
        }
    }

    pub fn key(&self) -> Option<&str> {
        let keyid = self.inner.id as isize;
        unsafe {
            let raw_name = (*self.file.header().id[BCF_DT_ID as usize].offset(keyid)).key;
            CStr::from_ptr(raw_name).to_str().ok()
        }
    }

    pub fn value(&self) -> TypedValue {
        TypedValue::from_type_and_raw_data(
            self.inner.type_,
            self.inner.p,
            self.inner.size as u32 * self.nsamples,
        )
    }
}