zaeleus / noodles

Bioinformatics I/O libraries in Rust
MIT License
482 stars 52 forks source link

sam/record/data/field/tag: Add const initializer #204

Closed zaeleus closed 11 months ago

zaeleus commented 11 months ago

How do we avoid the .parse().unwrap() on? I'd like to have the whole expression be constant.

    data.insert(
        "x1".parse().unwrap(),
        noodles::sam::record::data::field::Value::from(value),
    );

Originally posted by @nh13 in https://github.com/zaeleus/noodles/issues/197#issuecomment-1724912818


sam::record::data::field::Tag should have a const fn initializer to use in const contexts, e.g.,

const X1: Tag = match Tag::new([b'X', b'1']) {
    Some(tag) => tag,
    None => unreachable!(),
};

data.insert(X1, Value::from(0));
nh13 commented 11 months ago

Thank you! Wow!

zaeleus commented 11 months ago

This is now available in noodles 0.52.0 / noodles-sam 0.43.0.