Skip to content

Commit

Permalink
Merge pull request #457 from johanhelsing/fix-direct-implementation-o…
Browse files Browse the repository at this point in the history
…f-to-string

fix: error: direct implementation of `ToString`
  • Loading branch information
johanhelsing authored Jul 11, 2024
2 parents 6001c1e + 86b03d6 commit f28ef09
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions matchbox_protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ cfg_if! {
if #[cfg(feature = "json")] {
pub type JsonPeerRequest = PeerRequest<serde_json::Value>;
pub type JsonPeerEvent = PeerEvent<serde_json::Value>;
use std::fmt;

impl ToString for JsonPeerRequest {
fn to_string(&self) -> String {
serde_json::to_string(self).expect("error serializing message")

impl fmt::Display for JsonPeerRequest {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", serde_json::to_string(self).map_err(|_| fmt::Error)?)
}
}
impl std::str::FromStr for JsonPeerRequest {
Expand All @@ -48,9 +50,9 @@ cfg_if! {
}
}

impl ToString for JsonPeerEvent {
fn to_string(&self) -> String {
serde_json::to_string(self).expect("error serializing message")
impl fmt::Display for JsonPeerEvent {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", serde_json::to_string(self).map_err(|_| fmt::Error)?)
}
}
impl std::str::FromStr for JsonPeerEvent {
Expand Down

0 comments on commit f28ef09

Please sign in to comment.