Skip to content

Commit

Permalink
store value as GString, implement as_gstring, to_gstring methods
Browse files Browse the repository at this point in the history
  • Loading branch information
yggverse committed Jan 18, 2025
1 parent cac5440 commit 946ff48
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/client/connection/response/meta/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down

0 comments on commit 946ff48

Please sign in to comment.