From 38c64ab16cc374c650f59cc473e8656b27ef1138 Mon Sep 17 00:00:00 2001 From: Michael Macias Date: Wed, 20 Sep 2023 10:29:06 -0500 Subject: [PATCH] sam/header/record/value/map: Add mutable getter for other fields --- noodles-sam/CHANGELOG.md | 3 +++ noodles-sam/src/header/record/value/map.rs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/noodles-sam/CHANGELOG.md b/noodles-sam/CHANGELOG.md index 11d3098e0..c1d7d2562 100644 --- a/noodles-sam/CHANGELOG.md +++ b/noodles-sam/CHANGELOG.md @@ -4,6 +4,9 @@ ### Added + * sam/header/record/value/map: Add mutable getter for other fields + (`Map::other_fields_mut`). + * sam/record/data/field/tag: Add `const` initializer (`Tag::new`) ([#204]). [#204]: https://github.com/zaeleus/noodles/issues/204 diff --git a/noodles-sam/src/header/record/value/map.rs b/noodles-sam/src/header/record/value/map.rs index 159d07be0..c07fa7f05 100644 --- a/noodles-sam/src/header/record/value/map.rs +++ b/noodles-sam/src/header/record/value/map.rs @@ -52,6 +52,25 @@ where pub fn other_fields(&self) -> &OtherFields { &self.other_fields } + + /// Returns a mutable reference to the nonstandard fields in the map. + /// + /// # Example + /// + /// ``` + /// use noodles_sam::header::record::value::{map::{Header, Tag}, Map}; + /// + /// let nd = match Tag::try_from([b'n', b'd']) { + /// Ok(Tag::Other(tag)) => tag, + /// _ => unreachable!(), + /// }; + /// + /// let mut map = Map::
::new(Default::default()); + /// map.other_fields_mut().insert(nd, String::from("noodles")); + /// ``` + pub fn other_fields_mut(&mut self) -> &mut OtherFields { + &mut self.other_fields + } } impl Default for Map