NumericValue

Enum NumericValue 

Source
pub enum NumericValue {
    U8(u8),
    U16(u16),
    U32(u32),
    F32(u32),
}
Expand description

Represents a numeric value in the context of the bcf-reader.

Variants§

§

U8(u8)

Represents an unsigned 8-bit integer value.

§

U16(u16)

Represents an unsigned 16-bit integer value.

§

U32(u32)

Represents an unsigned 32-bit integer value.

§

F32(u32)

Represents a 32-bit floating-point value. (Note that a u32 is used to hold the bits for the f32 value)

Implementations§

Source§

impl NumericValue

Source

pub fn int_val(&self) -> Option<u32>

Returns the integer value if the NumericValue is an unsigned integer and not missing.

§Examples
use bcf_reader::NumericValue;

let value = NumericValue::U8(42);
assert_eq!(value.int_val(), Some(42u32));

let missing_value = NumericValue::U8(0x80u8);
assert_eq!(missing_value.int_val(), None);
Source

pub fn float_val(&self) -> Option<f32>

Returns the floating-point value if the NumericValue is a 32-bit float and not missing.

§Examples
use bcf_reader::NumericValue;

let value = NumericValue::F32(3.14f32.to_bits());
assert_eq!(value.float_val(), Some(3.14f32));

let missing_value = NumericValue::F32(0x7F800001);
let missing_value2 = NumericValue::F32(0x7F800001);
assert_eq!(missing_value.float_val(), missing_value2.float_val());
dbg!(&missing_value);
assert_eq!(missing_value.float_val(), None);
Source

pub fn gt_val(&self) -> (bool, bool, bool, u32)

Returns a tuple representing the GT value.

The tuple contains the following elements:

  • noploidy: A boolean indicating if the ploidy is missing (for individuals with fewer ploids compared to individuals with the maximum ploidy).
  • dot: A boolean indicating if the genotype call is a dot.
  • phased: A boolean indicating if the allele is phased (the first allele of a call is always unphased).
  • allele: The allele value (index).
§Examples
use bcf_reader::NumericValue;

let value = NumericValue::U8(3);
assert_eq!(value.gt_val(), (false, false, true, 0));

let value = NumericValue::U8(5);
assert_eq!(value.gt_val(), (false, false, true, 1));

let missing_value = NumericValue::U8(0);
assert_eq!(missing_value.gt_val(), (false, true, false, u32::MAX));

Trait Implementations§

Source§

impl Debug for NumericValue

Source§

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

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

impl Default for NumericValue

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<u16> for NumericValue

Source§

fn from(value: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for NumericValue

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for NumericValue

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for NumericValue

Source§

fn eq(&self, other: &NumericValue) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for NumericValue

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

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>,

Source§

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.