Enum rust_htslib::bam::record::Aux

source ·
pub enum Aux<'a> {
Show 18 variants Char(u8), I8(i8), U8(u8), I16(i16), U16(u16), I32(i32), U32(u32), Float(f32), Double(f64), String(&'a str), HexByteArray(&'a str), ArrayI8(AuxArray<'a, i8>), ArrayU8(AuxArray<'a, u8>), ArrayI16(AuxArray<'a, i16>), ArrayU16(AuxArray<'a, u16>), ArrayI32(AuxArray<'a, i32>), ArrayU32(AuxArray<'a, u32>), ArrayFloat(AuxArray<'a, f32>),
}
Expand description

Auxiliary record data

The specification allows a wide range of types to be stored as an auxiliary data field of a BAM record.

Please note that the Aux::Double variant is not part of the specification, but it is supported by htslib.

§Examples

use rust_htslib::{
    bam,
    bam::record::{Aux, AuxArray},
    errors::Error,
};

//Set up BAM record
let bam_header = bam::Header::new();
let mut record = bam::Record::from_sam(
    &mut bam::HeaderView::from_header(&bam_header),
    "ali1\t4\t*\t0\t0\t*\t*\t0\t0\tACGT\tFFFF".as_bytes(),
)
.unwrap();

// Add an integer field
let aux_integer_field = Aux::I32(1234);
record.push_aux(b"XI", aux_integer_field).unwrap();

match record.aux(b"XI") {
    Ok(value) => {
        // Typically, callers expect an aux field to be of a certain type.
        // If that's not the case, the value can be `match`ed exhaustively.
        if let Aux::I32(v) = value {
            assert_eq!(v, 1234);
        }
    }
    Err(e) => {
        panic!("Error reading aux field: {}", e);
    }
}

// Add an array field
let array_like_data = vec![0.4, 0.3, 0.2, 0.1];
let slice_of_data = &array_like_data;
let aux_array: AuxArray<f32> = slice_of_data.into();
let aux_array_field = Aux::ArrayFloat(aux_array);
record.push_aux(b"XA", aux_array_field).unwrap();

if let Ok(Aux::ArrayFloat(array)) = record.aux(b"XA") {
    let read_array = array.iter().collect::<Vec<_>>();
    assert_eq!(read_array, array_like_data);
} else {
    panic!("Could not read array data");
}

Variants§

§

Char(u8)

§

I8(i8)

§

U8(u8)

§

I16(i16)

§

U16(u16)

§

I32(i32)

§

U32(u32)

§

Float(f32)

§

Double(f64)

§

String(&'a str)

§

HexByteArray(&'a str)

§

ArrayI8(AuxArray<'a, i8>)

§

ArrayU8(AuxArray<'a, u8>)

§

ArrayI16(AuxArray<'a, i16>)

§

ArrayU16(AuxArray<'a, u16>)

§

ArrayI32(AuxArray<'a, i32>)

§

ArrayU32(AuxArray<'a, u32>)

§

ArrayFloat(AuxArray<'a, f32>)

Trait Implementations§

source§

impl<'a> Debug for Aux<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> PartialEq for Aux<'a>

source§

fn eq(&self, other: &Aux<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> Send for Aux<'a>

source§

impl<'a> StructuralPartialEq for Aux<'a>

source§

impl<'a> Sync for Aux<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Aux<'a>

§

impl<'a> RefUnwindSafe for Aux<'a>

§

impl<'a> Unpin for Aux<'a>

§

impl<'a> UnwindSafe for Aux<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.