From 5c0b8bf38681164ab4f8872a624ae4c3fce83ed9 Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 31 Oct 2024 05:32:10 +0200 Subject: [PATCH] separate constructors --- src/client/response/data/text.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/client/response/data/text.rs b/src/client/response/data/text.rs index 10ed150..0a3a2b4 100644 --- a/src/client/response/data/text.rs +++ b/src/client/response/data/text.rs @@ -22,15 +22,22 @@ pub struct Text { impl Text { // Constructors - /// Create new `Self` with options - pub fn new(data: GString) -> Self { - Self { data } + /// Create new `Self` + pub fn new() -> Self { + Self { + data: GString::new(), + } + } + + /// Create new `Self` from string + pub fn from_string(data: &str) -> Self { + Self { data: data.into() } } /// Create new `Self` from UTF-8 buffer pub fn from_utf8(buffer: &[u8]) -> Result)> { match GString::from_utf8(buffer.into()) { - Ok(data) => Ok(Self::new(data)), + Ok(data) => Ok(Self::from_string(&data)), Err(_) => Err((Error::Decode, None)), } }