Skip to content

Commit

Permalink
Relax a self bound
Browse files Browse the repository at this point in the history
  • Loading branch information
seamlik committed Mar 10, 2024
1 parent 0f295b8 commit d1420e1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
8 changes: 3 additions & 5 deletions main/src/response_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use futures_channel::mpsc::UnboundedSender;
use futures_util::stream::BoxStream;
use futures_util::StreamExt;
use mockall::automock;
use std::fmt::Debug;
use std::net::IpAddr;
use std::net::SocketAddrV6;
use tansa_protocol::response_collector_service_server::ResponseCollectorService;
Expand All @@ -18,12 +17,11 @@ use tonic::Status;
use tower_layer::Identity;

#[automock]
pub trait ResponseCollector: Debug {
pub trait ResponseCollector {
fn get_port(&self) -> u16;
fn collect(self: Box<Self>) -> BoxStream<'static, Result<Service, tonic::transport::Error>>;
fn collect(self) -> BoxStream<'static, Result<Service, tonic::transport::Error>>;
}

#[derive(Debug)]
pub struct GrpcResponseCollector {
tcp: TcpListenerStream,
port: u16,
Expand Down Expand Up @@ -61,7 +59,7 @@ impl ResponseCollector for GrpcResponseCollector {
fn get_port(&self) -> u16 {
self.port
}
fn collect(self: Box<Self>) -> BoxStream<'static, Result<Service, tonic::transport::Error>> {
fn collect(self) -> BoxStream<'static, Result<Service, tonic::transport::Error>> {
log::info!("Collecting responses at port {}", self.get_port());
crate::stream::join(
self.grpc.serve_with_incoming(self.tcp),
Expand Down
4 changes: 1 addition & 3 deletions main/src/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub struct Service {
pub fn scan(discovery_port: u16) -> impl Stream<Item = Result<Service, ScanError>> {
GrpcResponseCollector::new()
.err_into()
.map_ok(Box::new)
.map_ok(move |c| {
scan_internal(
discovery_port,
Expand All @@ -39,7 +38,7 @@ pub fn scan(discovery_port: u16) -> impl Stream<Item = Result<Service, ScanError

fn scan_internal(
discovery_port: u16,
response_collector: Box<dyn ResponseCollector>,
response_collector: impl ResponseCollector,
multicast_sender: impl MulticastSender + Send + 'static,
multicast_receiver: impl MulticastPacketReceiver + Send + 'static,
) -> BoxStream<'static, Result<Service, ScanError>> {
Expand Down Expand Up @@ -167,7 +166,6 @@ mod test {
.map(Ok)
.boxed()
});
let response_collector = Box::new(response_collector);

let mut multicast_sender = MockMulticastSender::default();
multicast_sender
Expand Down

0 comments on commit d1420e1

Please sign in to comment.