diff --git a/src/cheetah_string.rs b/src/cheetah_string.rs index c440f8e..36c3d98 100644 --- a/src/cheetah_string.rs +++ b/src/cheetah_string.rs @@ -7,7 +7,7 @@ use std::ops::Deref; use std::str::FromStr; use std::sync::Arc; -const EMPTY_STRING: &str = ""; +pub const EMPTY_STRING: &str = ""; #[derive(Clone)] #[repr(transparent)] @@ -195,6 +195,12 @@ impl AsRef<[u8]> for CheetahString { } } +impl AsRef for CheetahString { + fn as_ref(&self) -> &CheetahString { + self + } +} + impl From<&String> for CheetahString { fn from(s: &String) -> Self { CheetahString::from_slice(s) diff --git a/src/serde.rs b/src/serde.rs index f0c4a78..010a221 100644 --- a/src/serde.rs +++ b/src/serde.rs @@ -1,4 +1,4 @@ -use crate::cheetah_string::InnerString; +use crate::cheetah_string::{InnerString, EMPTY_STRING}; use crate::CheetahString; use serde::de::{Error, Unexpected, Visitor}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; @@ -14,7 +14,7 @@ impl Serialize for CheetahString { InnerString::ArcVecString(s) => serializer.serialize_bytes(s), #[cfg(feature = "bytes")] InnerString::Bytes(bytes) => serializer.serialize_bytes(bytes.as_ref()), - InnerString::Empty => serializer.serialize_bytes(&[]), + InnerString::Empty => serializer.serialize_str(EMPTY_STRING), } } }