Skip to content

Commit

Permalink
feat(octez): implement serialize for endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
huancheng-trili committed Nov 15, 2024
1 parent 3f06119 commit 7bed1ce
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions crates/octez/src/async/endpoint.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![allow(dead_code)]
use std::fmt::{self, Display};

use http::{uri::Scheme, Uri};
use serde::Serialize;
use std::fmt::{self, Display};

#[derive(Debug, Clone, PartialEq)]
pub struct Endpoint {
Expand Down Expand Up @@ -32,6 +31,15 @@ impl Endpoint {
}
}

impl Serialize for Endpoint {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(&self.to_string())
}
}

impl Default for Endpoint {
fn default() -> Self {
Self::localhost(80)
Expand Down Expand Up @@ -121,4 +129,13 @@ mod tests {
let endpoint = Endpoint::localhost(8765);
assert!(endpoint.to_string().contains("http://localhost:8765"));
}

#[test]
fn serialize() {
let endpoint = Endpoint::localhost(8765);
assert_eq!(
serde_json::to_string(&endpoint).unwrap(),
"\"http://localhost:8765\""
)
}
}

0 comments on commit 7bed1ce

Please sign in to comment.