crate::use_native_or_external!(List);
crate::use_native_or_external!(StringPtr);
use super::Bytes;
impl Bytes {
pub fn empty() -> Self {
Self::new(list![])
}
pub fn as_str_lossy(&self) -> Result<&str, std::str::Utf8Error> {
std::str::from_utf8(self.as_raw())
}
pub fn to_string_lossy(&self) -> StringPtr {
String::from_utf8_lossy(self.as_raw()).into_owned().into()
}
pub fn to_string(&self) -> Result<StringPtr, std::string::FromUtf8Error> {
String::from_utf8(self.as_raw().to_vec()).map(|s| s.into())
}
pub fn into_string(self) -> Result<StringPtr, std::string::FromUtf8Error> {
String::from_utf8(self.into_raw().into()).map(|s| s.into())
}
pub fn is_valid_utf8(&self) -> bool {
std::str::from_utf8(self.as_raw()).is_ok()
}
pub fn is_empty(&self) -> bool {
self.as_raw().is_empty()
}
pub fn len(&self) -> usize {
self.as_raw().len()
}
pub fn clear(&mut self) {
self.set_raw(list![])
}
}