mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-03-31 17:15:31 +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 {
|
||||
// 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<Self, (Error, Option<&str>)> {
|
||||
match GString::from_utf8(buffer.into()) {
|
||||
Ok(data) => Ok(Self::new(data)),
|
||||
Ok(data) => Ok(Self::from_string(&data)),
|
||||
Err(_) => Err((Error::Decode, None)),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue