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

deps: upgrade to rkyv v0.8 #409

Merged
merged 2 commits into from
Dec 29, 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
4 changes: 2 additions & 2 deletions compact_str/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ diesel = { version = "2", optional = true, default-features = false }
markup = { version = "0.13", optional = true, default-features = false }
proptest = { version = "1", optional = true, default-features = false, features = ["std"] }
quickcheck = { version = "1", optional = true, default-features = false }
rkyv = { version = "0.7", optional = true, default-features = false, features = ["size_32"] }
rkyv = { version = "0.8", optional = true, default-features = false }
serde = { version = "1", optional = true, default-features = false, features = ["derive", "alloc"] }
smallvec = { version = "1", optional = true, features = ["union"] }
sqlx = { version = "0.8", optional = true, default-features = false }
Expand All @@ -56,7 +56,7 @@ proptest = { version = "1", default-features = false, features = ["std"] }
quickcheck = { version = "1", default-features = false }
quickcheck_macros = "1"
rayon = "1"
rkyv = { version = "0.7", default-features = false, features = ["alloc", "size_32"] }
rkyv = { version = "0.8.8" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
test-case = "3"
Expand Down
46 changes: 26 additions & 20 deletions compact_str/src/features/rkyv.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#![cfg_attr(docsrs, doc(cfg(feature = "rkyv")))]

use rkyv::rancor::{Fallible, Source};
use rkyv::string::{ArchivedString, StringResolver};
use rkyv::{Archive, Deserialize, DeserializeUnsized, Fallible, Serialize, SerializeUnsized};
use rkyv::{Archive, Deserialize, DeserializeUnsized, Place, Serialize, SerializeUnsized};

use crate::CompactString;

Expand All @@ -10,14 +11,15 @@ impl Archive for CompactString {
type Resolver = StringResolver;

#[inline]
unsafe fn resolve(&self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived) {
ArchivedString::resolve_from_str(self.as_str(), pos, resolver, out);
fn resolve(&self, resolver: Self::Resolver, out: Place<Self::Archived>) {
ArchivedString::resolve_from_str(self.as_str(), resolver, out);
}
}

impl<S: Fallible + ?Sized> Serialize<S> for CompactString
where
str: SerializeUnsized<S>,
S::Error: Source,
{
#[inline]
fn serialize(&self, serializer: &mut S) -> Result<Self::Resolver, S::Error> {
Expand Down Expand Up @@ -53,7 +55,8 @@ impl PartialOrd<CompactString> for ArchivedString {
mod tests {
use alloc::string::String;

use rkyv::Deserialize;
use rkyv::string::ArchivedString;
use rkyv::{rancor, Archive};
use test_strategy::proptest;

use crate::CompactString;
Expand All @@ -63,20 +66,20 @@ mod tests {
fn test_roundtrip() {
const VALUE: &str = "Hello, 🌍!";

let bytes_compact = rkyv::to_bytes::<_, 32>(&CompactString::from(VALUE)).unwrap();
let bytes_control = rkyv::to_bytes::<_, 32>(&String::from(VALUE)).unwrap();
let bytes_compact = rkyv::to_bytes::<rancor::Error>(&CompactString::from(VALUE)).unwrap();
let bytes_control = rkyv::to_bytes::<rancor::Error>(&String::from(VALUE)).unwrap();
assert_eq!(&*bytes_compact, &*bytes_control);

let archived = unsafe { rkyv::archived_root::<CompactString>(&bytes_compact) };
let compact: CompactString = archived.deserialize(&mut rkyv::Infallible).unwrap();
let control: String = archived.deserialize(&mut rkyv::Infallible).unwrap();
let archived = rkyv::access::<ArchivedString, rancor::Error>(&bytes_compact).unwrap();
let compact = rkyv::deserialize::<CompactString, rancor::Error>(archived).unwrap();
let control = rkyv::deserialize::<String, rancor::Error>(archived).unwrap();
assert_eq!(archived, VALUE);
assert_eq!(compact, VALUE);
assert_eq!(control, VALUE);

let archived = unsafe { rkyv::archived_root::<String>(&bytes_compact) };
let compact: CompactString = archived.deserialize(&mut rkyv::Infallible).unwrap();
let control: String = archived.deserialize(&mut rkyv::Infallible).unwrap();
let archived = rkyv::access::<ArchivedString, rancor::Error>(&bytes_compact).unwrap();
let compact = rkyv::deserialize::<CompactString, rancor::Error>(archived).unwrap();
let control = rkyv::deserialize::<String, rancor::Error>(archived).unwrap();
assert_eq!(archived, VALUE);
assert_eq!(compact, VALUE);
assert_eq!(control, VALUE);
Expand All @@ -85,20 +88,23 @@ mod tests {
#[cfg_attr(miri, ignore)]
#[proptest]
fn proptest_roundtrip(s: String) {
let bytes_compact = rkyv::to_bytes::<_, 32>(&CompactString::from(&s)).unwrap();
let bytes_control = rkyv::to_bytes::<_, 32>(&s).unwrap();
let bytes_compact = rkyv::to_bytes::<rancor::Error>(&CompactString::from(&s)).unwrap();
let bytes_control = rkyv::to_bytes::<rancor::Error>(&s).unwrap();
assert_eq!(&*bytes_compact, &*bytes_control);

let archived = unsafe { rkyv::archived_root::<CompactString>(&bytes_compact) };
let compact: CompactString = archived.deserialize(&mut rkyv::Infallible).unwrap();
let control: String = archived.deserialize(&mut rkyv::Infallible).unwrap();
let archived =
rkyv::access::<<CompactString as Archive>::Archived, rancor::Error>(&bytes_compact)
.unwrap();
let compact = rkyv::deserialize::<CompactString, rancor::Error>(archived).unwrap();
let control = rkyv::deserialize::<String, rancor::Error>(archived).unwrap();
assert_eq!(archived, &s);
assert_eq!(compact, s);
assert_eq!(control, s);

let archived = unsafe { rkyv::archived_root::<String>(&bytes_compact) };
let compact: CompactString = archived.deserialize(&mut rkyv::Infallible).unwrap();
let control: String = archived.deserialize(&mut rkyv::Infallible).unwrap();
let archived =
rkyv::access::<<String as Archive>::Archived, rancor::Error>(&bytes_compact).unwrap();
let compact = rkyv::deserialize::<CompactString, rancor::Error>(archived).unwrap();
let control = rkyv::deserialize::<String, rancor::Error>(archived).unwrap();
assert_eq!(archived, &s);
assert_eq!(compact, s);
assert_eq!(control, s);
Expand Down
Loading