change Data struct, replace GString with String, implement Display trait

This commit is contained in:
yggverse 2025-01-18 02:51:06 +02:00
parent 962558c123
commit 5dd78dd43d

View file

@ -4,16 +4,12 @@
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 {
pub value: GString,
}
pub struct Data(String);
impl Data {
// Constructors
@ -47,9 +43,9 @@ impl Data {
}
// Assumes the bytes are valid UTF-8
match GString::from_utf8(bytes) {
Ok(value) => Ok(match value.is_empty() {
false => Some(Self { value }),
match String::from_utf8(bytes) {
Ok(data) => Ok(match data.is_empty() {
false => Some(Self(data)),
true => None,
}),
Err(e) => Err(Error::Decode(e)),
@ -59,3 +55,9 @@ impl Data {
}
}
}
impl std::fmt::Display for Data {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}