From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 69A5963CC3 for ; Fri, 17 Jul 2020 08:34:55 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 61A3E19B7E for ; Fri, 17 Jul 2020 08:34:55 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 5A1FD19B66 for ; Fri, 17 Jul 2020 08:34:53 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 2721440982 for ; Fri, 17 Jul 2020 08:34:53 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Fri, 17 Jul 2020 08:34:50 +0200 Message-Id: <20200717063451.19207-3-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200717063451.19207-1-d.csapak@proxmox.com> References: <20200717063451.19207-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.008 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods NO_DNS_FOR_FROM 0.379 Envelope sender has no MX or A DNS records RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [websocket.rs] Subject: [pbs-devel] [PATCH proxmox 3/4] proxmox/tools/websocket: fix some clippy warnings X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Jul 2020 06:34:55 -0000 * reformat docs * use &mut [u8] instead of Box<[u8]> (conversion can be done automatically) * use: let foo = if condition { A } else { B }; instead of matching on a boolean condition * rename WaitingForData to WaitingForFuture so that not all variants of the enum end with Data Signed-off-by: Dominik Csapak --- proxmox/src/tools/websocket.rs | 35 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/proxmox/src/tools/websocket.rs b/proxmox/src/tools/websocket.rs index b548b47..80312f3 100644 --- a/proxmox/src/tools/websocket.rs +++ b/proxmox/src/tools/websocket.rs @@ -1,8 +1,7 @@ //! Websocket helpers //! -//! Provides methods to read and write from websockets -//! The reader and writer take a reader/writer with AsyncRead/AsyncWrite -//! respectively and provides the same +//! Provides methods to read and write from websockets The reader and writer take a reader/writer +//! with AsyncRead/AsyncWrite respectively and provides the same use std::pin::Pin; use std::task::{Context, Poll}; @@ -124,7 +123,7 @@ impl OpCode { } } -fn mask_bytes(mask: Option<[u8; 4]>, data: &mut Box<[u8]>) { +fn mask_bytes(mask: Option<[u8; 4]>, data: &mut [u8]) { let mask = match mask { Some([0,0,0,0]) | None => return, Some(mask) => mask, @@ -289,10 +288,7 @@ impl AsyncWrite for WebSocketWriter { ) -> Poll> { let this = Pin::get_mut(self); - let frametype = match this.text { - true => OpCode::Text, - false => OpCode::Binary, - }; + let frametype = if this.text { OpCode::Text } else { OpCode::Binary }; if this.frame.is_none() { // create frame buf @@ -459,16 +455,15 @@ impl FrameHeader { )); } - let mask = match mask_bit { - true => { - if len < mask_offset + 4 { - return Ok(Err(mask_offset + 4 - len)); - } - let mut mask = [0u8; 4]; - mask.copy_from_slice(&data[mask_offset as usize..payload_offset as usize]); - Some(mask) + let mask = if mask_bit { + if len < mask_offset + 4 { + return Ok(None); } - false => None, + let mut mask = [0u8; 4]; + mask.copy_from_slice(&data[mask_offset as usize..payload_offset as usize]); + Some(mask) + } else { + None }; Ok(Some(FrameHeader { @@ -524,7 +519,7 @@ struct ReadResult { enum ReaderState { NoData, - WaitingForData(Pin>> + Send + 'static>>), + WaitingForFuture(Pin>> + Send + 'static>>), HaveData, } @@ -558,9 +553,9 @@ impl AsyncRead for WebSocketReader .map(move |len| ReadResult { len, reader, buffer }) }; - this.state = ReaderState::WaitingForData(future.boxed()); + this.state = ReaderState::WaitingForFuture(future.boxed()); }, - ReaderState::WaitingForData(ref mut future) => { + ReaderState::WaitingForFuture(ref mut future) => { match ready!(future.as_mut().poll(cx)) { Ok(ReadResult { len, reader, buffer }) => { this.reader = Some(reader); -- 2.20.1