From 32c238da4d27a8241ba7144f26c7026db6e7cfe5 Mon Sep 17 00:00:00 2001 From: yggverse Date: Fri, 25 Oct 2024 20:55:30 +0300 Subject: [PATCH] return entire self taken --- src/client/socket/connection.rs | 2 +- src/client/socket/connection/input.rs | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/client/socket/connection.rs b/src/client/socket/connection.rs index bf187ab..28bdf42 100644 --- a/src/client/socket/connection.rs +++ b/src/client/socket/connection.rs @@ -52,7 +52,7 @@ impl Connection { callback( self, match input { - Ok(buffer) => Ok(buffer.to_utf8()), + Ok(this) => Ok(this.buffer().to_utf8()), Err(error) => Err(match error { input::Error::BufferOverflow => Error::InputBufferOverflow, input::Error::BufferWrite => Error::InputBufferWrite, diff --git a/src/client/socket/connection/input.rs b/src/client/socket/connection/input.rs index 16ba332..8938129 100644 --- a/src/client/socket/connection/input.rs +++ b/src/client/socket/connection/input.rs @@ -31,6 +31,8 @@ impl Input { /// Synchronously read all bytes from `gio::InputStream` to `input::Buffer` /// + /// Return `Self` with `buffer` updated on success + /// /// Options: /// * `cancellable` https://docs.gtk.org/gio/class.Cancellable.html /// * `chunk` max bytes to read per chunk (256 by default) @@ -38,7 +40,7 @@ impl Input { mut self, cancelable: Option, chunk: Option, - ) -> Result { + ) -> Result { loop { // Continue bytes reading match self.stream.read_bytes( @@ -55,7 +57,7 @@ impl Input { Ok(bytes) => { // No bytes were read, end of stream if bytes.len() == 0 { - return Ok(self.buffer); + return Ok(self); } // Save chunk to buffer @@ -70,9 +72,10 @@ impl Input { } } - /// Asynchronously read all bytes from `gio::InputStream` to `input::Buffer`, + /// Asynchronously read all bytes from `gio::InputStream` to `input::Buffer` /// - /// applies `callback` function on last byte reading complete. + /// * applies `callback` function on last byte reading complete; + /// * return `Self` with `buffer` updated on success /// /// Options: /// * `cancellable` https://docs.gtk.org/gio/class.Cancellable.html (`None::<&Cancellable>` by default) @@ -84,7 +87,7 @@ impl Input { cancelable: Option, priority: Option, chunk: Option, - callback: impl FnOnce(Result) + 'static, + callback: impl FnOnce(Result) + 'static, ) { // Continue bytes reading self.stream.clone().read_bytes_async( @@ -106,7 +109,7 @@ impl Input { Ok(bytes) => { // No bytes were read, end of stream if bytes.len() == 0 { - return callback(Ok(self.buffer)); + return callback(Ok(self)); } // Save chunk to buffer