Skip to content

Commit

Permalink
gff/directive_buf/value: Add conversion from string
Browse files Browse the repository at this point in the history
  • Loading branch information
zaeleus committed Dec 5, 2024
1 parent 955d8c7 commit edf6970
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
7 changes: 2 additions & 5 deletions noodles-gff/src/directive_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl FromStr for DirectiveBuf {
.and_then(|s| s.parse().map_err(ParseError::InvalidGenomeBuild))
.map(Value::GenomeBuild)
.map(Some)?,
_ => components.next().map(|s| Value::String(s.into())),
_ => components.next().map(Value::from),
};

Ok(Self {
Expand All @@ -133,10 +133,7 @@ mod tests {

assert_eq!(
"##noodles gff".parse(),
Ok(DirectiveBuf::new(
"noodles",
Some(Value::String(String::from("gff"))),
)),
Ok(DirectiveBuf::new("noodles", Some(Value::from("gff")))),
);
}
}
12 changes: 12 additions & 0 deletions noodles-gff/src/directive_buf/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,15 @@ pub enum Value {
/// Any other directive value.
String(String),
}

impl From<&str> for Value {
fn from(s: &str) -> Self {
Value::String(s.into())
}
}

impl From<String> for Value {
fn from(s: String) -> Self {
Value::String(s)
}
}
2 changes: 1 addition & 1 deletion noodles-gff/src/io/writer/line/directive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ mod tests {

t(
&mut buf,
&DirectiveBuf::new("noodles", Some(Value::String(String::from("gff")))),
&DirectiveBuf::new("noodles", Some(Value::from("gff"))),
b"##noodles gff",
)?;

Expand Down

0 comments on commit edf6970

Please sign in to comment.