Struct noodles_vcf::variant::record_buf::info::Info

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

A variant record record info fields buffer.

Implementations§

source§

impl Info

source

pub fn clear(&mut self)

Removes all fields from the info map.

This does not affect the capacity of the map.

§Examples
use noodles_vcf::variant::{
    record::{info::field::key, Info as _},
    record_buf::{info::field::Value, Info},
};

let ns = (String::from(key::SAMPLES_WITH_DATA_COUNT), Some(Value::Integer(2)));
let dp = (String::from(key::TOTAL_DEPTH), Some(Value::Integer(13)));
let mut info: Info = [ns, dp].into_iter().collect();
assert!(!info.is_empty());

info.clear();
assert!(info.is_empty());
source

pub fn get<K>(&self, key: &K) -> Option<Option<&Value>>
where K: Hash + Equivalent<String> + ?Sized,

Returns a reference to the field value with the given key.

§Examples
use noodles_vcf::variant::{
    record::info::field::key,
    record_buf::{info::field::Value, Info},
};

let ns = (String::from(key::SAMPLES_WITH_DATA_COUNT), Some(Value::Integer(2)));
let dp = (String::from(key::TOTAL_DEPTH), Some(Value::Integer(13)));
let info: Info = [ns, dp.clone()].into_iter().collect();

assert_eq!(info.get(key::TOTAL_DEPTH), Some(Some(&Value::Integer(13))));
assert!(info.get(key::ALLELE_FREQUENCIES).is_none());
source

pub fn get_mut<K>(&mut self, key: &K) -> Option<&mut Option<Value>>
where K: Hash + Equivalent<String> + ?Sized,

Returns a mutable reference to the field value with the given key.

§Examples
use noodles_vcf::variant::{
    record::info::field::key,
    record_buf::{info::field::Value, Info},
};

let ns = (String::from(key::SAMPLES_WITH_DATA_COUNT), Some(Value::Integer(2)));
let dp = (String::from(key::TOTAL_DEPTH), Some(Value::Integer(13)));
let mut info: Info = [ns, dp].into_iter().collect();

if let Some(value) = info.get_mut(key::TOTAL_DEPTH) {
    *value = Some(Value::Integer(8));
}

assert_eq!(info.get(key::TOTAL_DEPTH), Some(Some(&Value::Integer(8))));
source

pub fn get_index(&self, i: usize) -> Option<(&String, Option<&Value>)>

Returns a reference to the field at the given index.

§Examples
use noodles_vcf::variant::{
    record::info::field::key,
    record_buf::{info::field::Value, Info},
};

let ns = (String::from(key::SAMPLES_WITH_DATA_COUNT), Some(Value::Integer(2)));
let dp = (String::from(key::TOTAL_DEPTH), Some(Value::Integer(13)));
let info: Info = [ns, dp].into_iter().collect();

assert_eq!(
    info.get_index(1),
    Some((&String::from(key::TOTAL_DEPTH), Some(&Value::Integer(13))))
);

assert!(info.get_index(5).is_none());
source

pub fn get_index_mut( &mut self, i: usize, ) -> Option<(&String, &mut Option<Value>)>

Returns a mutable reference to the field at the given index.

§Examples
use noodles_vcf::variant::{
    record::info::field::key,
    record_buf::{info::field::Value, Info},
};

let ns = (String::from(key::SAMPLES_WITH_DATA_COUNT), Some(Value::Integer(2)));
let dp = (String::from(key::TOTAL_DEPTH), Some(Value::Integer(13)));
let mut info: Info = [ns, dp].into_iter().collect();

if let Some((_, value)) = info.get_index_mut(1) {
    *value = Some(Value::Integer(8));
}

assert_eq!(
    info.get_index(1),
    Some((&String::from(key::TOTAL_DEPTH), Some(&Value::Integer(8))))
);
source

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

Inserts a field into the info map.

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

§Examples
use noodles_vcf::variant::{
    record::{info::field::key, Info as _},
    record_buf::{info::field::Value, Info},
};

let ns = (String::from(key::SAMPLES_WITH_DATA_COUNT), Some(Value::Integer(2)));
let mut info: Info = [ns].into_iter().collect();
assert_eq!(info.len(), 1);

info.insert(String::from(key::TOTAL_DEPTH), Some(Value::Integer(13)));

assert_eq!(info.len(), 2);
assert_eq!(info.get(key::TOTAL_DEPTH), Some(Some(&Value::Integer(13))));
source

pub fn keys(&self) -> impl Iterator<Item = &String>

Returns an iterator over all keys.

§Examples
use noodles_vcf::variant::{
    record::info::field::key,
    record_buf::{info::field::Value, Info},
};

let ns = (String::from(key::SAMPLES_WITH_DATA_COUNT), Some(Value::Integer(2)));
let dp = (String::from(key::TOTAL_DEPTH), Some(Value::Integer(13)));
let info: Info = [ns, dp].into_iter().collect();

let mut keys = info.keys();

assert_eq!(keys.next(), Some(&String::from(key::SAMPLES_WITH_DATA_COUNT)));
assert_eq!(keys.next(), Some(&String::from(key::TOTAL_DEPTH)));
assert!(keys.next().is_none());
source

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

Returns an iterator over all values.

§Examples
use noodles_vcf::variant::{
    record::info::field::key,
    record_buf::{info::field::Value, Info},
};

let ns = (String::from(key::SAMPLES_WITH_DATA_COUNT), Some(Value::Integer(2)));
let dp = (String::from(key::TOTAL_DEPTH), Some(Value::Integer(13)));
let info: Info = [ns, dp].into_iter().collect();

let mut values = info.values();

assert_eq!(values.next(), Some(Some(&Value::Integer(2))));
assert_eq!(values.next(), Some(Some(&Value::Integer(13))));
assert!(values.next().is_none());

Trait Implementations§

source§

impl AsMut<IndexMap<String, Option<Value>>> for Info

source§

fn as_mut(&mut self) -> &mut IndexMap<String, Option<Value>>

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl AsRef<IndexMap<String, Option<Value>>> for Info

source§

fn as_ref(&self) -> &IndexMap<String, Option<Value>>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for Info

source§

fn clone(&self) -> Info

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 Debug for Info

source§

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

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

impl Default for Info

source§

fn default() -> Info

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

impl Extend<(String, Option<Value>)> for Info

source§

fn extend<T: IntoIterator<Item = (String, Option<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<(String, Option<Value>)> for Info

source§

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

Creates a value from an iterator. Read more
source§

impl Info for &Info

source§

fn is_empty(&self) -> bool

Returns whether there are any fields.
source§

fn len(&self) -> usize

Returns the number of fields.
source§

fn get<'a, 'h: 'a>( &'a self, header: &'h Header, key: &str, ) -> Option<Result<Option<Value<'a>>>>

Returns the value of the given key.
source§

fn iter<'a, 'h: 'a>( &'a self, _: &'h Header, ) -> Box<dyn Iterator<Item = Result<(&'a str, Option<Value<'a>>)>> + 'a>

Returns an iterator over fields.
source§

impl Info for Info

source§

fn is_empty(&self) -> bool

Returns whether there are any fields.
source§

fn len(&self) -> usize

Returns the number of fields.
source§

fn get<'a, 'h: 'a>( &'a self, header: &'h Header, key: &str, ) -> Option<Result<Option<Value<'a>>>>

Returns the value of the given key.
source§

fn iter<'a, 'h: 'a>( &'a self, _: &'h Header, ) -> Box<dyn Iterator<Item = Result<(&'a str, Option<Value<'a>>)>> + 'a>

Returns an iterator over fields.
source§

impl PartialEq for Info

source§

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

Auto Trait Implementations§

§

impl Freeze for Info

§

impl RefUnwindSafe for Info

§

impl Send for Info

§

impl Sync for Info

§

impl Unpin for Info

§

impl UnwindSafe for Info

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