Struct noodles_bgzf::virtual_position::VirtualPosition

source ·
pub struct VirtualPosition(/* private fields */);
Expand description

A BGZF virtual position.

A virtual position is a 64-bit unsigned integer representing both the position in the compressed stream and position in the uncompressed block data. The compressed position is typically at the start of a block.

The compressed position is the first six most significant bytes; and the uncompressed position, the last two least significant bytes. For example, for the virtual position 10253313912875616487:

                      compressed position
                       |               |
10253313912875616487 = 8e 4b 16 ad eb 85 88 e7
                                         |   |
                                 uncompressed position

The compressed position is at 156453154188165 (8e 4b 16 ad eb 85); and the uncompressed position, 35047 (88 e7).

This is also called a virtual file offset; or, simply, a virtual offset.

Implementations§

source§

impl VirtualPosition

source

pub const MIN: Self = _

The minimum value of a virtual position.

source

pub const MAX: Self = _

The maximum value of a virtual position.

source

pub const fn new(compressed_pos: u64, uncompressed_pos: u16) -> Option<Self>

Creates a virtual position if the compressed position is valid.

§Examples
use noodles_bgzf::VirtualPosition;
assert_eq!(VirtualPosition::new(0, 0), Some(VirtualPosition::MIN));
assert!(VirtualPosition::new(1 << 48, 0).is_none());
source

pub const fn compressed(self) -> u64

The position in the compressed BGZF stream.

This is typically at the start of a block.

The maximum value of a compressed position is 281474976710655 (2^48 - 1).

§Examples
use noodles_bgzf as bgzf;
let virtual_position = bgzf::VirtualPosition::from(3741638);
assert_eq!(virtual_position.compressed(), 57);
source

pub const fn uncompressed(self) -> u16

The position in the uncompressed block data.

The maximum value of an uncompressed position is 65535 (2^16 - 1).

§Examples
use noodles_bgzf as bgzf;
let virtual_position = bgzf::VirtualPosition::from(3741638);
assert_eq!(virtual_position.uncompressed(), 6086);

Trait Implementations§

source§

impl Clone for VirtualPosition

source§

fn clone(&self) -> VirtualPosition

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for VirtualPosition

source§

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

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

impl Default for VirtualPosition

source§

fn default() -> VirtualPosition

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

impl From<VirtualPosition> for (u64, u16)

source§

fn from(pos: VirtualPosition) -> Self

Converts to this type from the input type.
source§

impl From<VirtualPosition> for u64

source§

fn from(pos: VirtualPosition) -> Self

Converts to this type from the input type.
source§

impl From<u64> for VirtualPosition

source§

fn from(pos: u64) -> Self

Converts to this type from the input type.
source§

impl Ord for VirtualPosition

source§

fn cmp(&self, other: &VirtualPosition) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for VirtualPosition

source§

fn eq(&self, other: &VirtualPosition) -> 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 PartialOrd for VirtualPosition

source§

fn partial_cmp(&self, other: &VirtualPosition) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl TryFrom<(u64, u16)> for VirtualPosition

source§

fn try_from(pos: (u64, u16)) -> Result<Self, Self::Error>

Converts a (compressed position, uncompressed position) tuple to a virtual position.

§Examples
use noodles_bgzf as bgzf;
let virtual_position = bgzf::VirtualPosition::try_from((57, 6086));
assert_eq!(virtual_position, Ok(bgzf::VirtualPosition::from(3741638)));
source§

type Error = TryFromU64U16TupleError

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

impl Copy for VirtualPosition

source§

impl Eq for VirtualPosition

source§

impl StructuralPartialEq for VirtualPosition

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.