pub struct Data { /* private fields */ }
Expand description
SAM record data.
This is also called optional fields.
Implementations
sourceimpl Data
impl Data
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of data fields.
Examples
use noodles_sam::record::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 data fields.
Examples
use noodles_sam::record::Data;
let data = Data::default();
assert!(data.is_empty());
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Removes all data fields from the data map.
This does not affect the capacity of the map.
Examples
use noodles_sam::record::{data::{field::{Tag, Value}, Field}, Data};
let mut data = Data::try_from(vec![
Field::new(Tag::AlignmentHitCount, Value::Int(1)),
])?;
assert_eq!(data.len(), 1);
data.clear();
assert!(data.is_empty());
sourcepub fn get(&self, tag: Tag) -> Option<&Field>
pub fn get(&self, tag: Tag) -> Option<&Field>
Returns a reference to the field of the given tag.
Examples
use noodles_sam::record::{data::{field::{Tag, Value}, Field}, Data};
let nh = Field::new(Tag::AlignmentHitCount, Value::Int(1));
let data = Data::try_from(vec![nh.clone()])?;
assert_eq!(data.get(Tag::AlignmentHitCount), Some(&nh));
assert!(data.get(Tag::ReadGroup).is_none());
sourcepub fn get_index_of(&self, tag: Tag) -> Option<usize>
pub fn get_index_of(&self, tag: Tag) -> Option<usize>
Returns the index of the field of the given tag.
Examples
use noodles_sam::record::{data::{field::{Tag, Value}, Field}, Data};
let nh = Field::new(Tag::AlignmentHitCount, Value::Int(1));
let data = Data::try_from(vec![nh])?;
assert_eq!(data.get_index_of(Tag::AlignmentHitCount), Some(0));
assert!(data.get_index_of(Tag::ReadGroup).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::record::{data::{field::{Tag, Value}, Field}, Data};
let nh = Field::new(Tag::AlignmentHitCount, Value::Int(1));
let data = Data::try_from(vec![nh])?;
let mut keys = data.keys();
assert_eq!(keys.next(), Some(Tag::AlignmentHitCount));
assert!(keys.next().is_none());
sourcepub fn values(&self) -> impl Iterator<Item = &Field>
pub fn values(&self) -> impl Iterator<Item = &Field>
Returns an iterator over all fields.
Examples
use noodles_sam::record::{data::{field::{Tag, Value}, Field}, Data};
let nh = Field::new(Tag::AlignmentHitCount, Value::Int(1));
let data = Data::try_from(vec![nh.clone()])?;
let mut values = data.values();
assert_eq!(values.next(), Some(&nh));
assert!(values.next().is_none());
sourcepub fn insert(&mut self, field: Field) -> Option<Field>
pub fn insert(&mut self, field: Field) -> Option<Field>
Inserts a field into the data 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::record::{data::{field::{Tag, Value}, Field}, Data};
let mut data = Data::default();
let nh = Field::new(Tag::AlignmentHitCount, Value::Int(1));
data.insert(nh);
sourcepub fn remove(&mut self, tag: Tag) -> Option<Field>
pub fn remove(&mut self, tag: Tag) -> Option<Field>
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::record::{data::{field::{Tag, Value}, Field}, Data};
let nh = Field::new(Tag::AlignmentHitCount, Value::Int(1));
let rg = Field::new(Tag::ReadGroup, Value::String(String::from("rg0")));
let md = Field::new(Tag::AlignmentScore, Value::Int(98));
let mut data = Data::try_from(vec![nh.clone(), rg.clone(), md.clone()])?;
assert_eq!(data.remove(Tag::AlignmentHitCount), Some(nh));
assert!(data.remove(Tag::Comment).is_none());
let expected = Data::try_from(vec![md, rg])?;
assert_eq!(data, expected);
Trait Implementations
impl StructuralPartialEq for Data
Auto Trait Implementations
impl RefUnwindSafe for Data
impl Send for Data
impl Sync for Data
impl Unpin for Data
impl UnwindSafe for Data
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more