mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-04-02 18:15:37 +00:00
separate constructors
This commit is contained in:
parent
97b0317509
commit
5c0b8bf386
1 changed files with 11 additions and 4 deletions
|
|
@ -22,15 +22,22 @@ pub struct Text {
|
||||||
impl Text {
|
impl Text {
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
/// Create new `Self` with options
|
/// Create new `Self`
|
||||||
pub fn new(data: GString) -> Self {
|
pub fn new() -> Self {
|
||||||
Self { data }
|
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
|
/// Create new `Self` from UTF-8 buffer
|
||||||
pub fn from_utf8(buffer: &[u8]) -> Result<Self, (Error, Option<&str>)> {
|
pub fn from_utf8(buffer: &[u8]) -> Result<Self, (Error, Option<&str>)> {
|
||||||
match GString::from_utf8(buffer.into()) {
|
match GString::from_utf8(buffer.into()) {
|
||||||
Ok(data) => Ok(Self::new(data)),
|
Ok(data) => Ok(Self::from_string(&data)),
|
||||||
Err(_) => Err((Error::Decode, None)),
|
Err(_) => Err((Error::Decode, None)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue