mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-03-31 17:15:31 +00:00
change Text structure, implement Display trait
This commit is contained in:
parent
946ff485be
commit
48c7676788
1 changed files with 9 additions and 7 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue