Clean up some todos (#441)

This commit is contained in:
David Pedersen 2021-11-01 23:36:17 +01:00 committed by GitHub
parent 3d07d40e02
commit 1b98328dc8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 23 deletions

View file

@ -87,7 +87,7 @@ use std::{
};
use tokio_tungstenite::{
tungstenite::{
self,
self as ts,
protocol::{self, WebSocketConfig},
},
WebSocketStream,
@ -468,35 +468,31 @@ pub enum Message {
}
impl Message {
fn into_tungstenite(self) -> tungstenite::Message {
// TODO: maybe some shorter way to do that?
fn into_tungstenite(self) -> ts::Message {
match self {
Self::Text(text) => tungstenite::Message::Text(text),
Self::Binary(binary) => tungstenite::Message::Binary(binary),
Self::Ping(ping) => tungstenite::Message::Ping(ping),
Self::Pong(pong) => tungstenite::Message::Pong(pong),
Self::Close(Some(close)) => {
tungstenite::Message::Close(Some(tungstenite::protocol::CloseFrame {
code: tungstenite::protocol::frame::coding::CloseCode::from(close.code),
reason: close.reason,
}))
}
Self::Close(None) => tungstenite::Message::Close(None),
Self::Text(text) => ts::Message::Text(text),
Self::Binary(binary) => ts::Message::Binary(binary),
Self::Ping(ping) => ts::Message::Ping(ping),
Self::Pong(pong) => ts::Message::Pong(pong),
Self::Close(Some(close)) => ts::Message::Close(Some(ts::protocol::CloseFrame {
code: ts::protocol::frame::coding::CloseCode::from(close.code),
reason: close.reason,
})),
Self::Close(None) => ts::Message::Close(None),
}
}
fn from_tungstenite(message: tungstenite::Message) -> Self {
// TODO: maybe some shorter way to do that?
fn from_tungstenite(message: ts::Message) -> Self {
match message {
tungstenite::Message::Text(text) => Self::Text(text),
tungstenite::Message::Binary(binary) => Self::Binary(binary),
tungstenite::Message::Ping(ping) => Self::Ping(ping),
tungstenite::Message::Pong(pong) => Self::Pong(pong),
tungstenite::Message::Close(Some(close)) => Self::Close(Some(CloseFrame {
ts::Message::Text(text) => Self::Text(text),
ts::Message::Binary(binary) => Self::Binary(binary),
ts::Message::Ping(ping) => Self::Ping(ping),
ts::Message::Pong(pong) => Self::Pong(pong),
ts::Message::Close(Some(close)) => Self::Close(Some(CloseFrame {
code: close.code.into(),
reason: close.reason,
})),
tungstenite::Message::Close(None) => Self::Close(None),
ts::Message::Close(None) => Self::Close(None),
}
}

View file

@ -109,6 +109,7 @@ use http_body::Empty;
use pin_project_lite::pin_project;
use std::marker::PhantomData;
use std::{
fmt,
future::Future,
pin::Pin,
task::{Context, Poll},
@ -274,7 +275,6 @@ where
/// A [`Service`] that accepts requests based on a [`MethodFilter`] and allows
/// chaining additional services.
#[derive(Debug)] // TODO(david): don't require debug for B
pub struct MethodRouter<S, F, B> {
pub(crate) method: MethodFilter,
pub(crate) svc: S,
@ -282,6 +282,20 @@ pub struct MethodRouter<S, F, B> {
pub(crate) _request_body: PhantomData<fn() -> B>,
}
impl<S, F, B> fmt::Debug for MethodRouter<S, F, B>
where
S: fmt::Debug,
F: fmt::Debug,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("MethodRouter")
.field("method", &self.method)
.field("svc", &self.svc)
.field("fallback", &self.fallback)
.finish()
}
}
impl<S, F, B> Clone for MethodRouter<S, F, B>
where
S: Clone,