all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox 3/4] proxmox/tools/websocket: fix some clippy warnings
Date: Fri, 17 Jul 2020 08:34:50 +0200	[thread overview]
Message-ID: <20200717063451.19207-3-d.csapak@proxmox.com> (raw)
In-Reply-To: <20200717063451.19207-1-d.csapak@proxmox.com>

* 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 <d.csapak@proxmox.com>
---
 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<W: AsyncWrite + Unpin> AsyncWrite for WebSocketWriter<W> {
     ) -> Poll<io::Result<usize>> {
         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<R> {
 
 enum ReaderState<R> {
     NoData,
-    WaitingForData(Pin<Box<dyn Future<Output = io::Result<ReadResult<R>>> + Send + 'static>>),
+    WaitingForFuture(Pin<Box<dyn Future<Output = io::Result<ReadResult<R>>> + Send + 'static>>),
     HaveData,
 }
 
@@ -558,9 +553,9 @@ impl<R: AsyncReadExt + Unpin + Send + 'static> AsyncRead for WebSocketReader<R>
                             .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





  parent reply	other threads:[~2020-07-17  6:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-17  6:34 [pbs-devel] [PATCH proxmox 1/4] proxmox/tools/websocket: introduce WebSocketError and use it Dominik Csapak
2020-07-17  6:34 ` [pbs-devel] [PATCH proxmox 2/4] proxmox/tools/websocket: improve error handling Dominik Csapak
2020-07-17  6:34 ` Dominik Csapak [this message]
2020-07-17  6:34 ` [pbs-devel] [PATCH proxmox 4/4] proxmox/tools/byte_buffer: improve read_from example Dominik Csapak
2020-07-17 10:12 ` [pbs-devel] [PATCH proxmox 1/4] proxmox/tools/websocket: introduce WebSocketError and use it Wolfgang Bumiller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200717063451.19207-3-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal