From 1b98328dc8cc02bd1d08efdb0694372cef28a7b8 Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Mon, 1 Nov 2021 23:36:17 +0100 Subject: [PATCH] Clean up some todos (#441) --- src/extract/ws.rs | 40 ++++++++++++--------------- src/routing/service_method_routing.rs | 16 ++++++++++- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/extract/ws.rs b/src/extract/ws.rs index c5a06989..5daee519 100644 --- a/src/extract/ws.rs +++ b/src/extract/ws.rs @@ -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), } } diff --git a/src/routing/service_method_routing.rs b/src/routing/service_method_routing.rs index 2dcb09d5..ccaf6c43 100644 --- a/src/routing/service_method_routing.rs +++ b/src/routing/service_method_routing.rs @@ -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 { pub(crate) method: MethodFilter, pub(crate) svc: S, @@ -282,6 +282,20 @@ pub struct MethodRouter { pub(crate) _request_body: PhantomData B>, } +impl fmt::Debug for MethodRouter +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 Clone for MethodRouter where S: Clone,