Skip to content

Commit

Permalink
Improve the fetcher revision API (#193)
Browse files Browse the repository at this point in the history
* Convert Revision to u32

* Parse revision

* Narrow revision parsing error type
  • Loading branch information
MOZGIII authored Dec 14, 2023
1 parent 190fbb2 commit 479ff67
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions chromiumoxide_fetcher/src/revision.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::fmt;

use crate::FetcherError;
use std::{fmt, num::ParseIntError};

/// A [`Revision`] represents a version of chromium.
///
Expand All @@ -16,14 +14,25 @@ impl From<u32> for Revision {
}
}

impl From<Revision> for u32 {
fn from(value: Revision) -> Self {
value.0
}
}

impl std::str::FromStr for Revision {
type Err = ParseIntError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
s.parse::<u32>().map(|v| Self(v))
}
}

impl TryFrom<String> for Revision {
type Error = FetcherError;
type Error = ParseIntError;

fn try_from(value: String) -> Result<Self, Self::Error> {
value
.parse::<u32>()
.map_err(|e| FetcherError::InvalidRevision(e))
.map(|v| Self(v))
value.parse()
}
}

Expand Down

0 comments on commit 479ff67

Please sign in to comment.