Skip to content

Commit b64537d

Browse files
authored
feat: HeaderRecord::push_tag: Value may be owned (#388)
The type of the value may be a ref or owned. Previously it must be a ref.
1 parent fb74387 commit b64537d

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/bam/header.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl<'a> HeaderRecord<'a> {
139139
/// * `tag` - the tag identifier
140140
/// * `value` - the value. Can be any type convertible into a string. Preferably numbers or
141141
/// strings.
142-
pub fn push_tag<V: ToString>(&mut self, tag: &'a [u8], value: &V) -> &mut Self {
142+
pub fn push_tag<V: ToString>(&mut self, tag: &'a [u8], value: V) -> &mut Self {
143143
self.tags.push((tag, value.to_string().into_bytes()));
144144
self
145145
}
@@ -156,3 +156,22 @@ impl<'a> HeaderRecord<'a> {
156156
out
157157
}
158158
}
159+
160+
#[cfg(test)]
161+
mod tests {
162+
use super::HeaderRecord;
163+
164+
#[test]
165+
fn test_push_tag() {
166+
let mut record = HeaderRecord::new(b"HD");
167+
record.push_tag(b"X1", 0);
168+
record.push_tag(b"X2", &0);
169+
170+
let x = "x".to_string();
171+
record.push_tag(b"X3", x.as_str());
172+
record.push_tag(b"X4", &x);
173+
record.push_tag(b"X5", x);
174+
175+
assert_eq!(record.to_bytes(), b"@HD\tX1:0\tX2:0\tX3:x\tX4:x\tX5:x");
176+
}
177+
}

0 commit comments

Comments
 (0)