diff --git a/src/client/response/data/text.rs b/src/client/response/data/text.rs index 85312d6..ba695ca 100644 --- a/src/client/response/data/text.rs +++ b/src/client/response/data/text.rs @@ -111,7 +111,7 @@ pub fn read_all_from_stream_async( // Continue bytes reading read_all_from_stream_async(buffer, stream, cancelable, priority, callback); } - Err(reason) => callback(Err(Error::InputStreamRead(reason))), + Err(reason) => callback(Err(Error::InputStream(reason))), }, ); } diff --git a/src/client/response/data/text/error.rs b/src/client/response/data/text/error.rs index 5de7592..423c19c 100644 --- a/src/client/response/data/text/error.rs +++ b/src/client/response/data/text/error.rs @@ -4,7 +4,7 @@ use std::fmt::{Display, Formatter, Result}; pub enum Error { BufferOverflow, Decode(std::string::FromUtf8Error), - InputStreamRead(glib::Error), + InputStream(glib::Error), } impl Display for Error { @@ -16,7 +16,7 @@ impl Display for Error { Self::Decode(reason) => { write!(f, "Decode error: {reason}") } - Self::InputStreamRead(reason) => { + Self::InputStream(reason) => { write!(f, "Input stream read error: {reason}") } } diff --git a/src/client/response/meta.rs b/src/client/response/meta.rs index 29d05bd..8cca009 100644 --- a/src/client/response/meta.rs +++ b/src/client/response/meta.rs @@ -147,7 +147,7 @@ pub fn read_from_stream_async( // Continue read_from_stream_async(buffer, stream, cancellable, priority, on_complete); } - Err((data, reason)) => on_complete(Err(Error::InputStreamRead(data, reason))), + Err((data, reason)) => on_complete(Err(Error::InputStream(data, reason))), }, ); } diff --git a/src/client/response/meta/error.rs b/src/client/response/meta/error.rs index 9688a4b..246fd48 100644 --- a/src/client/response/meta/error.rs +++ b/src/client/response/meta/error.rs @@ -3,7 +3,7 @@ use std::fmt::{Display, Formatter, Result}; #[derive(Debug)] pub enum Error { Data(super::data::Error), - InputStreamRead(Vec, glib::Error), + InputStream(Vec, glib::Error), Mime(super::mime::Error), Protocol, Status(super::status::Error), @@ -15,7 +15,7 @@ impl Display for Error { Self::Data(reason) => { write!(f, "Data error: {reason}") } - Self::InputStreamRead(_, reason) => { + Self::InputStream(_, reason) => { // @TODO write!(f, "Input stream error: {reason}") } diff --git a/src/gio/memory_input_stream.rs b/src/gio/memory_input_stream.rs index ce7bb47..6c451d0 100644 --- a/src/gio/memory_input_stream.rs +++ b/src/gio/memory_input_stream.rs @@ -20,7 +20,7 @@ pub fn from_stream_async( bytes_in_chunk: usize, bytes_total_limit: usize, on_chunk: impl Fn((Bytes, usize)) + 'static, - on_complete: impl FnOnce(Result)>) + 'static, + on_complete: impl FnOnce(Result) + 'static, ) { read_all_from_stream_async( MemoryInputStream::new(), @@ -43,7 +43,7 @@ pub fn read_all_from_stream_async( bytes: (usize, usize, usize), callback: ( impl Fn((Bytes, usize)) + 'static, - impl FnOnce(Result)>) + 'static, + impl FnOnce(Result) + 'static, ), ) { let (on_chunk, on_complete) = callback; @@ -63,7 +63,7 @@ pub fn read_all_from_stream_async( // Validate max size if bytes_total > bytes_total_limit { - return on_complete(Err((Error::BytesTotal, None))); + return on_complete(Err(Error::BytesTotal(bytes_total, bytes_total_limit))); } // No bytes were read, end of stream @@ -85,7 +85,7 @@ pub fn read_all_from_stream_async( ); } Err(reason) => { - on_complete(Err((Error::InputStream, Some(reason.message())))); + on_complete(Err(Error::InputStream(reason))); } }, ); diff --git a/src/gio/memory_input_stream/error.rs b/src/gio/memory_input_stream/error.rs index b5cda40..515d6c9 100644 --- a/src/gio/memory_input_stream/error.rs +++ b/src/gio/memory_input_stream/error.rs @@ -1,5 +1,20 @@ +use std::fmt::{Display, Formatter, Result}; + #[derive(Debug)] pub enum Error { - BytesTotal, - InputStream, + BytesTotal(usize, usize), + InputStream(glib::Error), +} + +impl Display for Error { + fn fmt(&self, f: &mut Formatter) -> Result { + match self { + Self::BytesTotal(total, limit) => { + write!(f, "Bytes total limit reached: {total} / {limit}") + } + Self::InputStream(reason) => { + write!(f, "Input stream error: {reason}") + } + } + } }