Skip to content

Commit

Permalink
Implement Display trait for DidDocument (print as json)
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Stas <[email protected]>
  • Loading branch information
Patrik-Stas committed Oct 22, 2023
1 parent 8a695d4 commit 37a2d0c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 8 additions & 1 deletion did_doc/src/schema/did_doc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::{collections::HashMap, fmt::Display};

use did_parser::{Did, DidUrl};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -42,6 +42,13 @@ pub struct DidDocument<E> {
extra: HashMap<String, Value>,
}

impl Display for DidDocument<()> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let json = serde_json::to_string(self).unwrap();
write!(f, "{}", json)
}
}

impl<E> DidDocument<E> {
pub fn builder(id: Did) -> DidDocumentBuilder<E> {
DidDocumentBuilder::new(id)
Expand Down
5 changes: 1 addition & 4 deletions did_doc/src/schema/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,7 @@ mod tests {
.add_service_type(service_type.clone())
.unwrap()
.add_service_type(service_type.clone())
.unwrap()
.build();

assert_eq!(service.service_type(), &OneOrList::One(service_type));
.unwrap_err();
}

#[test]
Expand Down

0 comments on commit 37a2d0c

Please sign in to comment.