Struct noodles_sam::alignment::record_buf::data::Data

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

An alignment record data buffer.

Implementations§

source§

impl Data

source

pub fn len(&self) -> usize

Returns the number of fields.

§Examples
use noodles_sam::alignment::record_buf::Data;
let data = Data::default();
assert_eq!(data.len(), 0);
source

pub fn is_empty(&self) -> bool

Returns whether there are any fields.

§Examples
use noodles_sam::alignment::record_buf::Data;
let data = Data::default();
assert!(data.is_empty());
source

pub fn clear(&mut self)

Removes all fields from the map.

This does not affect the internal capacity.

§Examples
use noodles_sam::alignment::{
    record::data::field::Tag,
    record_buf::{data::field::Value, Data},
};

let nh = (Tag::ALIGNMENT_HIT_COUNT, Value::from(1));
let mut data: Data = [nh].into_iter().collect();
assert_eq!(data.len(), 1);
data.clear();
assert!(data.is_empty());
source

pub fn get<K>(&self, tag: &K) -> Option<&Value>
where K: Equivalent<Tag>,

Returns a reference to the value of the given tag.

§Examples
use noodles_sam::alignment::{
    record::data::field::Tag,
    record_buf::{data::field::Value, Data},
};

let (tag, value) = (Tag::ALIGNMENT_HIT_COUNT, Value::from(1));
let data: Data = [(tag, value.clone())].into_iter().collect();

assert_eq!(data.get(&tag), Some(&value));
assert!(data.get(&Tag::READ_GROUP).is_none());
source

pub fn get_mut<K>(&mut self, tag: &K) -> Option<&mut Value>
where K: Equivalent<Tag>,

Returns a mutable reference to the value of the given tag.

§Examples
use noodles_sam::alignment::{
    record::data::field::Tag,
    record_buf::{data::field::Value, Data},
};

let tag = Tag::ALIGNMENT_HIT_COUNT;
let mut data: Data = [(tag, Value::from(1))].into_iter().collect();

if let Some(v) = data.get_mut(&tag) {
    *v = Value::from(2);
}

assert_eq!(data.get(&tag), Some(&Value::from(2)));
source

pub fn get_index_of<K>(&self, tag: &K) -> Option<usize>
where K: Equivalent<Tag>,

Returns the index of the field of the given tag.

§Examples
use noodles_sam::alignment::{
    record::data::field::Tag,
    record_buf::{data::field::Value, Data},
};

let nh = (Tag::ALIGNMENT_HIT_COUNT, Value::from(1));
let data: Data = [nh].into_iter().collect();

assert_eq!(data.get_index_of(&Tag::ALIGNMENT_HIT_COUNT), Some(0));
assert!(data.get_index_of(&Tag::READ_GROUP).is_none());
source

pub fn iter(&self) -> impl Iterator<Item = (Tag, &Value)>

Returns an iterator over all tag-value pairs.

§Examples
use noodles_sam::alignment::{
    record::data::field::Tag,
    record_buf::{data::field::Value, Data},
};

let (tag, value) = (Tag::ALIGNMENT_HIT_COUNT, Value::from(1));
let data: Data = [(tag, value.clone())].into_iter().collect();

let mut fields = data.iter();
assert_eq!(fields.next(), Some((tag, &value)));
assert!(fields.next().is_none());
source

pub fn keys(&self) -> impl Iterator<Item = Tag> + '_

Returns an iterator over all tags.

§Examples
use noodles_sam::alignment::{
    record::data::field::Tag,
    record_buf::{data::field::Value, Data},
};

let nh = (Tag::ALIGNMENT_HIT_COUNT, Value::from(1));
let data: Data = [nh].into_iter().collect();

let mut keys = data.keys();
assert_eq!(keys.next(), Some(Tag::ALIGNMENT_HIT_COUNT));
assert!(keys.next().is_none());
source

pub fn values(&self) -> impl Iterator<Item = &Value>

Returns an iterator over all values.

§Examples
use noodles_sam::alignment::{
    record::data::field::Tag,
    record_buf::{data::field::Value, Data},
};

let (tag, value) = (Tag::ALIGNMENT_HIT_COUNT, Value::from(1));
let data: Data = [(tag, value.clone())].into_iter().collect();

let mut values = data.values();
assert_eq!(values.next(), Some(&value));
assert!(values.next().is_none());
source

pub fn insert(&mut self, tag: Tag, value: Value) -> Option<(Tag, Value)>

Inserts a field into the map.

This uses the field tag as the key and field as the value.

If the tag already exists in the map, the existing field is replaced by the new one, and the existing field is returned.

§Examples
use noodles_sam::alignment::{
    record::data::field::Tag,
    record_buf::{data::field::Value, Data},
};

let mut data = Data::default();
data.insert(Tag::ALIGNMENT_HIT_COUNT, Value::from(1));
source

pub fn remove<K>(&mut self, tag: &K) -> Option<(Tag, Value)>
where K: Equivalent<Tag>,

Removes the field with the given tag.

The field is returned if it exists.

This works like Vec::swap_remove; it does not preserve the order but has a constant time complexity.

§Examples
use noodles_sam::alignment::{
    record::data::field::Tag,
    record_buf::{data::field::Value, Data},
};

let nh = (Tag::ALIGNMENT_HIT_COUNT, Value::from(1));
let rg = (Tag::READ_GROUP, Value::from("rg0"));
let md = (Tag::ALIGNMENT_SCORE, Value::from(98));
let mut data: Data = [nh.clone(), rg.clone(), md.clone()].into_iter().collect();

assert_eq!(data.remove(&Tag::ALIGNMENT_HIT_COUNT), Some(nh));
assert!(data.remove(&Tag::COMMENT).is_none());

let expected = [md, rg].into_iter().collect();
assert_eq!(data, expected);

Trait Implementations§

source§

impl Clone for Data

source§

fn clone(&self) -> Data

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 Data for &Data

source§

fn is_empty(&self) -> bool

Returns whether there are any fields.
source§

fn get(&self, tag: &Tag) -> Option<Result<Value<'_>>>

Returns the value for the given tag.
source§

fn iter(&self) -> Box<dyn Iterator<Item = Result<(Tag, Value<'_>)>> + '_>

Returns an iterator over fields.
source§

impl Data for Data

source§

fn is_empty(&self) -> bool

Returns whether there are any fields.
source§

fn get(&self, tag: &Tag) -> Option<Result<Value<'_>>>

Returns the value for the given tag.
source§

fn iter(&self) -> Box<dyn Iterator<Item = Result<(Tag, Value<'_>)>> + '_>

Returns an iterator over fields.
source§

impl Debug for Data

source§

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

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

impl Default for Data

source§

fn default() -> Data

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

impl Extend<(Tag, Value)> for Data

source§

fn extend<T: IntoIterator<Item = (Tag, Value)>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl FromIterator<(Tag, Value)> for Data

source§

fn from_iter<T: IntoIterator<Item = (Tag, Value)>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl PartialEq for Data

source§

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

Auto Trait Implementations§

§

impl Freeze for Data

§

impl RefUnwindSafe for Data

§

impl Send for Data

§

impl Sync for Data

§

impl Unpin for Data

§

impl UnwindSafe for Data

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

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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,

§

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

§

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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more