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
/// 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)