use crate::types::text::ToText;
use crate::types::Text;
use std::ops::Deref;
#[derive(Clone, Debug)]
pub struct TextBuilder(String);
impl TextBuilder {
pub fn new() -> TextBuilder {
Self(String::new())
}
pub fn with_capacity(capacity: usize) -> TextBuilder {
Self(String::with_capacity(capacity))
}
pub fn from_text<T: Into<Text>>(s: T) -> TextBuilder {
Self(s.into().to_string())
}
#[inline]
pub fn push_str(&mut self, s: &str) -> () {
self.0.push_str(s)
}
#[inline]
pub fn push_text<T: Into<Text>>(&mut self, s: T) -> () {
self.0.push_str(s.into().as_str())
}
#[inline]
pub fn into_text(self) -> Text {
self.0.to_text()
}
#[inline]
pub fn as_str(&self) -> &str {
self.0.as_str()
}
}
impl Deref for TextBuilder {
type Target = str;
fn deref(&self) -> &Self::Target {
self.0.as_str()
}
}