pub struct Data(/* private fields */);
Expand description
An alignment record data buffer.
Implementations§
Source§impl Data
impl Data
Sourcepub fn len(&self) -> usize
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);
Sourcepub fn is_empty(&self) -> bool
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());
Sourcepub fn clear(&mut self)
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());
Sourcepub fn get<K>(&self, tag: &K) -> Option<&Value>where
K: Equivalent<Tag>,
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());
Sourcepub fn get_mut<K>(&mut self, tag: &K) -> Option<&mut Value>where
K: Equivalent<Tag>,
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)));
Sourcepub fn get_index_of<K>(&self, tag: &K) -> Option<usize>where
K: Equivalent<Tag>,
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());
Sourcepub fn iter(&self) -> impl Iterator<Item = (Tag, &Value)>
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());
Sourcepub fn keys(&self) -> impl Iterator<Item = Tag> + '_
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());
Sourcepub fn values(&self) -> impl Iterator<Item = &Value>
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());
Sourcepub fn insert(&mut self, tag: Tag, value: Value) -> Option<(Tag, Value)>
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));
Sourcepub fn remove<K>(&mut self, tag: &K) -> Option<(Tag, Value)>where
K: Equivalent<Tag>,
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 Extend<(Tag, Value)> for Data
impl Extend<(Tag, Value)> for Data
Source§fn extend<T: IntoIterator<Item = (Tag, Value)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (Tag, Value)>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)