From 48c76767881c560a9ec20d60aecf2c620f3934af Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 19 Jan 2025 03:29:22 +0200 Subject: [PATCH] change `Text` structure, implement `Display` trait --- src/client/connection/response/data/text.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/client/connection/response/data/text.rs b/src/client/connection/response/data/text.rs index 2d3cf2c..ea7c07c 100644 --- a/src/client/connection/response/data/text.rs +++ b/src/client/connection/response/data/text.rs @@ -15,9 +15,7 @@ pub const BUFFER_CAPACITY: usize = 0x400; // 1024 pub const BUFFER_MAX_SIZE: usize = 0xfffff; // 1M /// Container for text-based response data -pub struct Text { - pub data: GString, -} +pub struct Text(GString); impl Default for Text { fn default() -> Self { @@ -30,14 +28,12 @@ impl Text { /// Create new `Self` pub fn new() -> Self { - Self { - data: GString::new(), - } + Self(GString::new()) } /// Create new `Self` from string pub fn from_string(data: &str) -> Self { - Self { data: data.into() } + Self(data.into()) } /// Create new `Self` from UTF-8 buffer @@ -68,6 +64,12 @@ impl Text { } } +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)