change Text structure, implement Display trait

This commit is contained in:
yggverse 2025-01-19 03:29:22 +02:00
parent 946ff485be
commit 48c7676788

View file

@ -15,9 +15,7 @@ pub const BUFFER_CAPACITY: usize = 0x400; // 1024
pub const BUFFER_MAX_SIZE: usize = 0xfffff; // 1M pub const BUFFER_MAX_SIZE: usize = 0xfffff; // 1M
/// Container for text-based response data /// Container for text-based response data
pub struct Text { pub struct Text(GString);
pub data: GString,
}
impl Default for Text { impl Default for Text {
fn default() -> Self { fn default() -> Self {
@ -30,14 +28,12 @@ impl Text {
/// Create new `Self` /// Create new `Self`
pub fn new() -> Self { pub fn new() -> Self {
Self { Self(GString::new())
data: GString::new(),
}
} }
/// Create new `Self` from string /// Create new `Self` from string
pub fn from_string(data: &str) -> Self { pub fn from_string(data: &str) -> Self {
Self { data: data.into() } Self(data.into())
} }
/// Create new `Self` from UTF-8 buffer /// 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 // Tools
/// Asynchronously read all bytes from [IOStream](https://docs.gtk.org/gio/class.IOStream.html) /// Asynchronously read all bytes from [IOStream](https://docs.gtk.org/gio/class.IOStream.html)