From 946ff485be45eda2fc5d3d0a659249f8203c489b Mon Sep 17 00:00:00 2001 From: yggverse Date: Sat, 18 Jan 2025 03:37:26 +0200 Subject: [PATCH] store value as `GString`, implement `as_gstring`, `to_gstring` methods --- src/client/connection/response/meta/data.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/client/connection/response/meta/data.rs b/src/client/connection/response/meta/data.rs index 3642847..d5eef6b 100644 --- a/src/client/connection/response/meta/data.rs +++ b/src/client/connection/response/meta/data.rs @@ -4,12 +4,14 @@ pub mod error; pub use error::Error; +use glib::GString; + /// Meta **data** holder /// /// For example, `value` could contain: /// * placeholder text for 10, 11 status /// * URL string for 30, 31 status -pub struct Data(String); +pub struct Data(GString); impl Data { // Constructors @@ -43,7 +45,7 @@ impl Data { } // Assumes the bytes are valid UTF-8 - match String::from_utf8(bytes) { + match GString::from_utf8(bytes) { Ok(data) => Ok(match data.is_empty() { false => Some(Self(data)), true => None, @@ -61,6 +63,16 @@ impl Data { pub fn as_str(&self) -> &str { self.0.as_str() } + + /// Get `Self` as `glib::GString` + pub fn as_gstring(&self) -> &GString { + &self.0 + } + + /// Get `glib::GString` copy of `Self` + pub fn to_gstring(&self) -> GString { + self.0.clone() + } } impl std::fmt::Display for Data {