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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Formats the value using the given formatter. Read more

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.