Skip to content

Commit ec67acb

Browse files
authored
Add Distribution::parse and impl FromStr based on it
1 parent 39490a9 commit ec67acb

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

src/distribution.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,10 @@ pub struct Distribution {
6868
pub description_content_type: Option<String>,
6969
}
7070

71-
impl FromStr for Distribution {
72-
type Err = Error;
73-
74-
fn from_str(s: &str) -> Result<Self, Self::Err> {
75-
let msg = mailparse::parse_mail(s.as_bytes())?;
71+
impl Distribution {
72+
/// Parse distribution metadata from metadata bytes
73+
pub fn parse(content: &[u8]) -> Result<Self, Error> {
74+
let msg = mailparse::parse_mail(content)?;
7675
let headers = msg.get_headers();
7776
let metadata_version = headers
7877
.get_first_value("Metadata-Version")
@@ -84,6 +83,14 @@ impl FromStr for Distribution {
8483
}
8584
}
8685

86+
impl FromStr for Distribution {
87+
type Err = Error;
88+
89+
fn from_str(s: &str) -> Result<Self, Self::Err> {
90+
Distribution::parse(s.as_bytes())
91+
}
92+
}
93+
8794
#[cfg(test)]
8895
mod tests {
8996
use super::Distribution;

0 commit comments

Comments
 (0)