Skip to content

Commit fbf4584

Browse files
committed
feat(rust/signed-doc): serialize DocumentRef to cbor value
1 parent 8c23786 commit fbf4584

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

rust/signed_doc/src/metadata/document_ref.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//! Catalyst Signed Document Metadata.
2+
use coset::cbor::Value;
3+
24
use super::UuidV7;
35

46
/// Reference to a Document.
@@ -19,11 +21,22 @@ pub enum DocumentRef {
1921
},
2022
}
2123

22-
impl TryFrom<&coset::cbor::Value> for DocumentRef {
24+
impl From<&DocumentRef> for Value {
25+
fn from(val: &DocumentRef) -> Self {
26+
match val {
27+
DocumentRef::Latest { id } => Value::from(*id),
28+
DocumentRef::WithVer { id, ver } => {
29+
Value::Array(vec![Value::from(*id), Value::from(*ver)])
30+
},
31+
}
32+
}
33+
}
34+
35+
impl TryFrom<&Value> for DocumentRef {
2336
type Error = anyhow::Error;
2437

2538
#[allow(clippy::indexing_slicing)]
26-
fn try_from(val: &coset::cbor::Value) -> anyhow::Result<DocumentRef> {
39+
fn try_from(val: &Value) -> anyhow::Result<DocumentRef> {
2740
if let Ok(id) = UuidV7::try_from(val) {
2841
Ok(DocumentRef::Latest { id })
2942
} else {

0 commit comments

Comments
 (0)