src/net: use to_string from Display trait for OutboundState and P2pState enums

This commit is contained in:
ghassmo
2022-03-08 21:27:30 +04:00
parent 573b858e67
commit bcd4dcc2ee
2 changed files with 34 additions and 22 deletions

View File

@@ -1,13 +1,15 @@
use async_executor::Executor;
use async_std::sync::Mutex;
use log::debug;
use serde_json::json;
use std::{
collections::{HashMap, HashSet},
fmt,
net::SocketAddr,
sync::Arc,
};
use async_executor::Executor;
use log::debug;
use serde_json::json;
use crate::{
error::{Error, Result},
net::{
@@ -37,14 +39,18 @@ enum P2pState {
Run,
}
impl P2pState {
fn to_string(&self) -> String {
match self {
Self::Open => "open".to_string(),
Self::Start => "start".to_string(),
Self::Started => "started".to_string(),
Self::Run => "run".to_string(),
}
impl fmt::Display for P2pState {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{}",
match self {
Self::Open => "open",
Self::Start => "start",
Self::Started => "started",
Self::Run => "run",
}
)
}
}

View File

@@ -1,13 +1,15 @@
use async_executor::Executor;
use async_std::{sync::Mutex, task::yield_now};
use async_trait::async_trait;
use log::{error, info};
use serde_json::json;
use std::{
fmt,
net::SocketAddr,
sync::{Arc, Weak},
};
use async_executor::Executor;
use async_trait::async_trait;
use log::{error, info};
use serde_json::json;
use crate::{
error::{Error, Result},
net::{
@@ -24,13 +26,17 @@ enum OutboundState {
Connected,
}
impl OutboundState {
fn to_string(&self) -> String {
match self {
Self::Open => "open".to_string(),
Self::Pending => "pending".to_string(),
Self::Connected => "connected".to_string(),
}
impl fmt::Display for OutboundState {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{}",
match self {
Self::Open => "open",
Self::Pending => "pending",
Self::Connected => "connected",
}
)
}
}