diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 986793f..c70c17a 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -7,7 +7,6 @@ #![feature( weak_counts, non_exhaustive, - try_trait, arbitrary_self_types, async_await, trait_alias, diff --git a/rpc/src/server/filter.rs b/rpc/src/server/filter.rs index 8b2ce9a..299b005 100644 --- a/rpc/src/server/filter.rs +++ b/rpc/src/server/filter.rs @@ -22,8 +22,7 @@ use log::{debug, info, trace}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; use std::sync::{Arc, Weak}; use std::{ - collections::hash_map::Entry, convert::TryInto, fmt, hash::Hash, io, marker::Unpin, ops::Try, - pin::Pin, + collections::hash_map::Entry, convert::TryInto, fmt, hash::Hash, io, marker::Unpin, pin::Pin, }; /// A single-threaded filter that drops channels based on per-key limits. @@ -161,31 +160,6 @@ impl TrackedChannel { } } -enum NewChannel { - Accepted(TrackedChannel), - Filtered(K), -} - -impl Try for NewChannel { - type Ok = TrackedChannel; - type Error = K; - - fn into_result(self) -> Result, K> { - match self { - NewChannel::Accepted(channel) => Ok(channel), - NewChannel::Filtered(k) => Err(k), - } - } - - fn from_error(k: K) -> Self { - NewChannel::Filtered(k) - } - - fn from_ok(channel: TrackedChannel) -> Self { - NewChannel::Accepted(channel) - } -} - impl ChannelFilter where K: fmt::Display + Eq + Hash + Clone, @@ -224,7 +198,7 @@ where K: fmt::Display + Eq + Hash + Clone + Unpin, F: Fn(&C) -> K, { - fn handle_new_channel(self: &mut Pin<&mut Self>, stream: C) -> NewChannel { + fn handle_new_channel(self: &mut Pin<&mut Self>, stream: C) -> Result, K> { let key = self.as_mut().keymaker()(&stream); let tracker = self.increment_channels_for_key(key.clone())?; let max = self.as_mut().channels_per_key(); @@ -236,7 +210,7 @@ where max ); - NewChannel::Accepted(TrackedChannel { + Ok(TrackedChannel { tracker, inner: stream, }) @@ -282,7 +256,7 @@ where fn poll_listener( mut self: Pin<&mut Self>, cx: &mut Context<'_>, - ) -> Poll>> { + ) -> Poll, K>>> { match ready!(self.as_mut().listener().poll_next_unpin(cx)) { Some(codec) => Poll::Ready(Some(self.handle_new_channel(codec))), None => Poll::Ready(None), @@ -320,10 +294,10 @@ where self.as_mut().poll_listener(cx), self.poll_closed_channels(cx), ) { - (Poll::Ready(Some(NewChannel::Accepted(channel))), _) => { + (Poll::Ready(Some(Ok(channel))), _) => { return Poll::Ready(Some(channel)); } - (Poll::Ready(Some(NewChannel::Filtered(_))), _) => { + (Poll::Ready(Some(Err(_))), _) => { continue; } (_, Poll::Ready(())) => continue,