From 4ee92645ca090d81712239d436831f1baf867187 Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 3 Feb 2025 13:38:34 +0200 Subject: [PATCH] remove deprecated features --- src/client/connection/response.rs | 1 - src/client/connection/response/data.rs | 7 -- src/client/connection/response/data/text.rs | 113 ------------------ .../connection/response/data/text/error.rs | 24 ---- 4 files changed, 145 deletions(-) delete mode 100644 src/client/connection/response/data.rs delete mode 100644 src/client/connection/response/data/text.rs delete mode 100644 src/client/connection/response/data/text/error.rs diff --git a/src/client/connection/response.rs b/src/client/connection/response.rs index 6c1cd7b..51c3c7e 100644 --- a/src/client/connection/response.rs +++ b/src/client/connection/response.rs @@ -1,5 +1,4 @@ pub mod certificate; -pub mod data; // @TODO deprecated pub mod error; pub mod failure; pub mod input; diff --git a/src/client/connection/response/data.rs b/src/client/connection/response/data.rs deleted file mode 100644 index 0009fe8..0000000 --- a/src/client/connection/response/data.rs +++ /dev/null @@ -1,7 +0,0 @@ -//! Gemini response could have different MIME type for data. -//! Use one of components below to parse response according to content type expected. -//! -//! * MIME type could be detected using `client::response::Meta` parser - -pub mod text; -pub use text::Text; diff --git a/src/client/connection/response/data/text.rs b/src/client/connection/response/data/text.rs deleted file mode 100644 index aaa8aa1..0000000 --- a/src/client/connection/response/data/text.rs +++ /dev/null @@ -1,113 +0,0 @@ -//! Tools for Text-based response - -pub mod error; -pub use error::Error; - -// Local dependencies -use gio::{ - prelude::{IOStreamExt, InputStreamExt}, - Cancellable, IOStream, -}; -use glib::{object::IsA, GString, Priority}; - -// Default limits -pub const BUFFER_CAPACITY: usize = 0x400; // 1024 -pub const BUFFER_MAX_SIZE: usize = 0xfffff; // 1M - -/// Container for text-based response data -pub struct Text(String); - -impl Default for Text { - fn default() -> Self { - Self::new() - } -} - -impl Text { - // Constructors - - /// Create new `Self` - pub fn new() -> Self { - Self(String::new()) - } - - /// Create new `Self` from string - pub fn from_string(data: &str) -> Self { - Self(data.into()) - } - - /// Create new `Self` from UTF-8 buffer - pub fn from_utf8(buffer: &[u8]) -> Result { - match GString::from_utf8(buffer.into()) { - Ok(data) => Ok(Self::from_string(&data)), - Err(e) => Err(Error::Decode(e)), - } - } - - /// Asynchronously create new `Self` from [IOStream](https://docs.gtk.org/gio/class.IOStream.html) - pub fn from_stream_async( - stream: impl IsA, - priority: Priority, - cancellable: Cancellable, - on_complete: impl FnOnce(Result) + 'static, - ) { - read_all_from_stream_async( - Vec::with_capacity(BUFFER_CAPACITY), - stream, - cancellable, - priority, - |result| match result { - Ok(buffer) => on_complete(Self::from_utf8(&buffer)), - Err(e) => on_complete(Err(e)), - }, - ); - } -} - -impl std::fmt::Display for Text { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{}", self.0) - } -} - -// Tools - -/// Asynchronously read all bytes from [IOStream](https://docs.gtk.org/gio/class.IOStream.html) -/// -/// Return UTF-8 buffer collected -/// * require `IOStream` reference to keep `Connection` active in async thread -pub fn read_all_from_stream_async( - mut buffer: Vec, - stream: impl IsA, - cancelable: Cancellable, - priority: Priority, - callback: impl FnOnce(Result, Error>) + 'static, -) { - stream.input_stream().read_bytes_async( - BUFFER_CAPACITY, - priority, - Some(&cancelable.clone()), - move |result| match result { - Ok(bytes) => { - // No bytes were read, end of stream - if bytes.len() == 0 { - return callback(Ok(buffer)); - } - - // Validate overflow - if buffer.len() + bytes.len() > BUFFER_MAX_SIZE { - return callback(Err(Error::BufferOverflow)); - } - - // Save chunks to buffer - for &byte in bytes.iter() { - buffer.push(byte); - } - - // Continue bytes reading - read_all_from_stream_async(buffer, stream, cancelable, priority, callback); - } - Err(e) => callback(Err(Error::InputStream(e))), - }, - ); -} diff --git a/src/client/connection/response/data/text/error.rs b/src/client/connection/response/data/text/error.rs deleted file mode 100644 index 4a853aa..0000000 --- a/src/client/connection/response/data/text/error.rs +++ /dev/null @@ -1,24 +0,0 @@ -use std::fmt::{Display, Formatter, Result}; - -#[derive(Debug)] -pub enum Error { - BufferOverflow, - Decode(std::string::FromUtf8Error), - InputStream(glib::Error), -} - -impl Display for Error { - fn fmt(&self, f: &mut Formatter) -> Result { - match self { - Self::BufferOverflow => { - write!(f, "Buffer overflow") - } - Self::Decode(e) => { - write!(f, "Decode error: {e}") - } - Self::InputStream(e) => { - write!(f, "Input stream read error: {e}") - } - } - } -}