Skip to content

Commit

Permalink
sam/header/record/value/map: Add mutable getter for other fields
Browse files Browse the repository at this point in the history
  • Loading branch information
zaeleus committed Sep 20, 2023
1 parent af6e381 commit 38c64ab
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions noodles-sam/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions noodles-sam/src/header/record/value/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ where
pub fn other_fields(&self) -> &OtherFields<I::StandardTag> {
&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::<Header>::new(Default::default());
/// map.other_fields_mut().insert(nd, String::from("noodles"));
/// ```
pub fn other_fields_mut(&mut self) -> &mut OtherFields<I::StandardTag> {
&mut self.other_fields
}
}

impl<I> Default for Map<I>
Expand Down

0 comments on commit 38c64ab

Please sign in to comment.