From 479ff676d6900e79ce5c497999c96d768f43c615 Mon Sep 17 00:00:00 2001 From: MOZGIII Date: Thu, 14 Dec 2023 14:30:25 -0300 Subject: [PATCH] Improve the fetcher revision API (#193) * Convert Revision to u32 * Parse revision * Narrow revision parsing error type --- chromiumoxide_fetcher/src/revision.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/chromiumoxide_fetcher/src/revision.rs b/chromiumoxide_fetcher/src/revision.rs index 394d2718..8768fc90 100644 --- a/chromiumoxide_fetcher/src/revision.rs +++ b/chromiumoxide_fetcher/src/revision.rs @@ -1,6 +1,4 @@ -use std::fmt; - -use crate::FetcherError; +use std::{fmt, num::ParseIntError}; /// A [`Revision`] represents a version of chromium. /// @@ -16,14 +14,25 @@ impl From for Revision { } } +impl From for u32 { + fn from(value: Revision) -> Self { + value.0 + } +} + +impl std::str::FromStr for Revision { + type Err = ParseIntError; + + fn from_str(s: &str) -> Result { + s.parse::().map(|v| Self(v)) + } +} + impl TryFrom for Revision { - type Error = FetcherError; + type Error = ParseIntError; fn try_from(value: String) -> Result { - value - .parse::() - .map_err(|e| FetcherError::InvalidRevision(e)) - .map(|v| Self(v)) + value.parse() } }