Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #55]🎨Fix CheetahString Serialize empty make Deserialize error🚀 #56

Merged
merged 1 commit into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/cheetah_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -195,6 +195,12 @@ impl AsRef<[u8]> for CheetahString {
}
}

impl AsRef<CheetahString> for CheetahString {
fn as_ref(&self) -> &CheetahString {
self
}
}

impl From<&String> for CheetahString {
fn from(s: &String) -> Self {
CheetahString::from_slice(s)
Expand Down
4 changes: 2 additions & 2 deletions src/serde.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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),
}
}
}
Expand Down
Loading