Skip to content

Commit

Permalink
Use into() for NamedObjectRef
Browse files Browse the repository at this point in the history
  • Loading branch information
666lcz committed Apr 19, 2022
1 parent e69c98f commit 9ca0158
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions sui/src/rest_gateway/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ pub struct NamedObjectRef {
}

impl NamedObjectRef {
pub fn from((object_id, version, digest): ObjectRef) -> Self {
Self {
object_id: object_id.to_hex(),
version: version.value(),
digest: Base64::encode_string(digest.as_ref()),
}
}

pub fn to_object_ref(self) -> Result<ObjectRef, anyhow::Error> {
Ok((
ObjectID::try_from(self.object_id)?,
Expand All @@ -57,6 +49,16 @@ impl NamedObjectRef {
}
}

impl From<ObjectRef> for NamedObjectRef {
fn from((object_id, version, digest): ObjectRef) -> Self {
Self {
object_id: object_id.to_hex(),
version: version.value(),
digest: Base64::encode_string(digest.as_ref()),
}
}
}

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase", transparent)]
pub struct JsonResponse<T>(pub T);
Expand Down Expand Up @@ -163,7 +165,7 @@ impl TryFrom<ObjectRead> for GetObjectInfoResponse {
match obj {
ObjectRead::Exists(object_ref, object, layout) => {
Ok(Self::Exists(ObjectExistsResponse {
object_ref: NamedObjectRef::from(object_ref),
object_ref: object_ref.into(),
object: object.to_json(&layout).map_err(|e| {
custom_http_error(StatusCode::INTERNAL_SERVER_ERROR, e.to_string())
})?,
Expand All @@ -172,7 +174,7 @@ impl TryFrom<ObjectRead> for GetObjectInfoResponse {
ObjectRead::NotExists(object_id) => Ok(Self::NotExists(ObjectNotExistsResponse {
object_id: object_id.to_hex(),
})),
ObjectRead::Deleted(obj_ref) => Ok(Self::Deleted(NamedObjectRef::from(obj_ref))),
ObjectRead::Deleted(obj_ref) => Ok(Self::Deleted(obj_ref.into())),
}
}
}

0 comments on commit 9ca0158

Please sign in to comment.