Skip to content

Commit

Permalink
revised id.parse::<AnyHash>() to AnyHash::from_str(&id)
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinrp committed May 7, 2024
1 parent 27d349f commit f62fe12
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion crates/api/src/v1/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::Status;
use indexmap::IndexMap;
use serde::{de::Unexpected, Deserialize, Serialize, Serializer};
use std::borrow::Cow;
use std::str::FromStr;
use thiserror::Error;
use warg_crypto::hash::AnyHash;

Expand Down Expand Up @@ -95,7 +96,7 @@ impl<'de> Deserialize<'de> for ContentError {
match RawError::<String>::deserialize(deserializer)? {
RawError::NotFound { status: _, ty, id } => match ty {
EntityType::ContentDigest => Ok(Self::ContentDigestNotFound(
id.parse::<AnyHash>().map_err(|_| {
AnyHash::from_str(&id).map_err(|_| {
serde::de::Error::invalid_value(Unexpected::Str(&id), &"a valid digest")
})?,
)),
Expand Down
3 changes: 2 additions & 1 deletion crates/api/src/v1/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::Status;
use indexmap::IndexMap;
use serde::{de::Unexpected, Deserialize, Serialize, Serializer};
use std::borrow::Cow;
use std::str::FromStr;
use thiserror::Error;
use warg_crypto::hash::AnyHash;
use warg_protocol::{
Expand Down Expand Up @@ -187,7 +188,7 @@ impl<'de> Deserialize<'de> for FetchError {
RawError::CheckpointNotFound { id, .. } => Ok(Self::CheckpointNotFound(id)),
RawError::NotFound { status: _, ty, id } => match ty {
EntityType::Log => Ok(Self::LogNotFound(
id.parse::<AnyHash>()
AnyHash::from_str(&id)
.map_err(|_| {
serde::de::Error::invalid_value(Unexpected::Str(&id), &"a valid log id")
})?
Expand Down
7 changes: 4 additions & 3 deletions crates/api/src/v1/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::Status;
use indexmap::IndexMap;
use serde::{de::Unexpected, Deserialize, Serialize, Serializer};
use std::borrow::Cow;
use std::str::FromStr;
use thiserror::Error;
use warg_crypto::hash::AnyHash;
use warg_protocol::{
Expand Down Expand Up @@ -286,14 +287,14 @@ impl<'de> Deserialize<'de> for PackageError {
}
RawError::NotFound { status: _, ty, id } => match ty {
EntityType::Log => Ok(Self::LogNotFound(
id.parse::<AnyHash>()
AnyHash::from_str(&id)
.map_err(|_| {
serde::de::Error::invalid_value(Unexpected::Str(&id), &"a valid log id")
})?
.into(),
)),
EntityType::Record => Ok(Self::RecordNotFound(
id.parse::<AnyHash>()
AnyHash::from_str(&id)
.map_err(|_| {
serde::de::Error::invalid_value(
Unexpected::Str(&id),
Expand All @@ -311,7 +312,7 @@ impl<'de> Deserialize<'de> for PackageError {
RawError::Conflict { status: _, ty, id } => match ty {
EntityType::NamespaceImport => Ok(Self::NamespaceImported(id.into_owned())),
EntityType::Record => Ok(Self::ConflictPendingPublish(
id.parse::<AnyHash>()
AnyHash::from_str(&id)
.map_err(|_| {
serde::de::Error::invalid_value(
Unexpected::Str(&id),
Expand Down

0 comments on commit f62fe12

Please sign in to comment.