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 B732063E0F for ; Fri, 17 Jul 2020 14:17:43 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B20991BD66 for ; Fri, 17 Jul 2020 14:17:13 +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 983AF1BD49 for ; Fri, 17 Jul 2020 14:17:11 +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 5C5D343136 for ; Fri, 17 Jul 2020 14:17:11 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Fri, 17 Jul 2020 14:17:09 +0200 Message-Id: <20200717121710.2297-3-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200717121710.2297-1-d.csapak@proxmox.com> References: <20200717121710.2297-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 v2 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 12:17:43 -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 Receiving so that not all variants of the enum end with Data Signed-off-by: Dominik Csapak --- changes from v1: * Receiving instead of WaitingForFuture 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 6d30061..e43c33e 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}; @@ -113,7 +112,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, @@ -278,10 +277,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 @@ -448,16 +444,15 @@ impl FrameHeader { )); } - let mask = match mask_bit { - true => { - if len < mask_offset + 4 { - return Ok(None); - } - 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 { @@ -513,7 +508,7 @@ struct ReadResult { enum ReaderState { NoData, - WaitingForData(Pin>> + Send + 'static>>), + Receiving(Pin>> + Send + 'static>>), HaveData, } @@ -547,9 +542,9 @@ impl AsyncRead for WebSocketReader .map(move |len| ReadResult { len, reader, buffer }) }; - this.state = ReaderState::WaitingForData(future.boxed()); + this.state = ReaderState::Receiving(future.boxed()); }, - ReaderState::WaitingForData(ref mut future) => { + ReaderState::Receiving(ref mut future) => { match ready!(future.as_mut().poll(cx)) { Ok(ReadResult { len, reader, buffer }) => { this.reader = Some(reader); -- 2.20.1