pub struct Data { /* private fields */ }
Expand description
SAM record data.
This is also called optional fields.
Implementations
Returns the number of data fields.
Examples
use noodles_sam::record::Data;
let data = Data::default();
assert_eq!(data.len(), 0);
Returns whether there are any data fields.
Examples
use noodles_sam::record::Data;
let data = Data::default();
assert!(data.is_empty());
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());
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());
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());
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());
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());
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);
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
Auto Trait Implementations
impl RefUnwindSafe for Data
impl UnwindSafe for Data
Blanket Implementations
Mutably borrows from an owned value. Read more