From fffdde09a305f87b203bb4c281c4fb57f3417383 Mon Sep 17 00:00:00 2001 From: Wil Boayue Date: Thu, 7 Nov 2024 23:12:49 -0800 Subject: [PATCH] clippy (#163) --- src/client.rs | 2 +- src/transport.rs | 60 +++++++++++++++++++++++++----------------------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/client.rs b/src/client.rs index 84c9bd6e..511ef76c 100644 --- a/src/client.rs +++ b/src/client.rs @@ -357,7 +357,7 @@ impl Client { /// } /// ``` pub fn contract_details(&self, contract: &Contract) -> Result, Error> { - Ok(contracts::contract_details(self, contract)?) + contracts::contract_details(self, contract) } /// Get current [FamilyCode]s for all accessible accounts. diff --git a/src/transport.rs b/src/transport.rs index 3764c0e0..7d073fc3 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -55,14 +55,16 @@ pub(crate) trait MessageBus: Send + Sync { } } +type Response = Result; + // For requests without an identifier, shared channels are created // to route request/response pairs based on message type. #[derive(Debug)] struct SharedChannels { // Maps an inbound reply to channel used to send responses. - senders: HashMap>>>>, + senders: HashMap>>>, // Maps an outbound request to channel used to receive responses. - receivers: HashMap>>>, + receivers: HashMap>>, } impl SharedChannels { @@ -83,7 +85,7 @@ impl SharedChannels { // Maps an outgoing message to incoming message(s) fn register(&mut self, outbound: OutgoingMessages, inbounds: &[IncomingMessages]) { - let (sender, receiver) = channel::unbounded::>(); + let (sender, receiver) = channel::unbounded::(); self.receivers.insert(outbound, Arc::new(receiver)); @@ -98,7 +100,7 @@ impl SharedChannels { } // Get receiver for specified message type. Panics if receiver not found. - fn get_receiver(&self, message_type: OutgoingMessages) -> Arc>> { + fn get_receiver(&self, message_type: OutgoingMessages) -> Arc> { let receiver = self .receivers .get(&message_type) @@ -123,7 +125,7 @@ impl SharedChannels { } // Notify all senders with a given message - fn notify_all(&self, message: &Result) { + fn notify_all(&self, message: &Response) { for senders in self.senders.values() { for sender in senders { if let Err(e) = sender.send(message.clone()) { @@ -145,9 +147,9 @@ pub enum Signal { pub struct TcpMessageBus { connection: Connection, handles: Mutex>>, - requests: SenderHash>, - orders: SenderHash>, - executions: SenderHash>, + requests: SenderHash, + orders: SenderHash, + executions: SenderHash, shared_channels: SharedChannels, signals_send: Sender, signals_recv: Receiver, @@ -211,7 +213,7 @@ impl TcpMessageBus { debug!("released order_id {}, orders.len()={}", order_id, self.orders.len()); } - fn read_message(&self) -> Result { + fn read_message(&self) -> Response { self.connection.read_message() } @@ -612,18 +614,18 @@ impl Send // Enables routing of response messages from TWS to Client #[derive(Debug, Default)] pub(crate) struct InternalSubscription { - receiver: Option>>, // requests with request ids receive responses via this channel - sender: Option>>, // requests with request ids receive responses via this channel - shared_receiver: Option>>>, // this channel is for responses that share channel based on message type - signaler: Option>, // for client to signal termination - pub(crate) request_id: Option, // initiating request id - pub(crate) order_id: Option, // initiating order id - pub(crate) message_type: Option, // initiating message type + receiver: Option>, // requests with request ids receive responses via this channel + sender: Option>, // requests with request ids receive responses via this channel + shared_receiver: Option>>, // this channel is for responses that share channel based on message type + signaler: Option>, // for client to signal termination + pub(crate) request_id: Option, // initiating request id + pub(crate) order_id: Option, // initiating order id + pub(crate) message_type: Option, // initiating message type } impl InternalSubscription { // Blocks until next message become available. - pub(crate) fn next(&self) -> Option> { + pub(crate) fn next(&self) -> Option { if let Some(receiver) = &self.receiver { Self::receive(receiver) } else if let Some(receiver) = &self.shared_receiver { @@ -634,7 +636,7 @@ impl InternalSubscription { } // Returns message if available or immediately returns None. - pub(crate) fn try_next(&self) -> Option> { + pub(crate) fn try_next(&self) -> Option { if let Some(receiver) = &self.receiver { Self::try_receive(receiver) } else if let Some(receiver) = &self.shared_receiver { @@ -645,7 +647,7 @@ impl InternalSubscription { } // Waits for next message until specified timeout. - pub(crate) fn next_timeout(&self, timeout: Duration) -> Option> { + pub(crate) fn next_timeout(&self, timeout: Duration) -> Option { if let Some(receiver) = &self.receiver { Self::timeout_receive(receiver, timeout) } else if let Some(receiver) = &self.shared_receiver { @@ -664,15 +666,15 @@ impl InternalSubscription { // TODO - shared sender } - fn receive(receiver: &Receiver>) -> Option> { + fn receive(receiver: &Receiver) -> Option { receiver.recv().ok() } - fn try_receive(receiver: &Receiver>) -> Option> { + fn try_receive(receiver: &Receiver) -> Option { receiver.try_recv().ok() } - fn timeout_receive(receiver: &Receiver>, timeout: Duration) -> Option> { + fn timeout_receive(receiver: &Receiver, timeout: Duration) -> Option { receiver.recv_timeout(timeout).ok() } } @@ -692,9 +694,9 @@ impl Drop for InternalSubscription { } pub(crate) struct SubscriptionBuilder { - receiver: Option>>, - sender: Option>>, - shared_receiver: Option>>>, + receiver: Option>, + sender: Option>, + shared_receiver: Option>>, signaler: Option>, order_id: Option, request_id: Option, @@ -714,17 +716,17 @@ impl SubscriptionBuilder { } } - pub(crate) fn receiver(mut self, receiver: Receiver>) -> Self { + pub(crate) fn receiver(mut self, receiver: Receiver) -> Self { self.receiver = Some(receiver); self } - pub(crate) fn sender(mut self, sender: Sender>) -> Self { + pub(crate) fn sender(mut self, sender: Sender) -> Self { self.sender = Some(sender); self } - pub(crate) fn shared_receiver(mut self, shared_receiver: Arc>>) -> Self { + pub(crate) fn shared_receiver(mut self, shared_receiver: Arc>) -> Self { self.shared_receiver = Some(shared_receiver); self } @@ -892,7 +894,7 @@ impl Connection { Ok(()) } - fn read_message(&self) -> Result { + fn read_message(&self) -> Response { let mut reader = self.reader.lock()?; let message_size = read_header(&reader)?;