Skip to content

Commit ef00726

Browse files
committed
fix: serde 1.0.225 compatibility
1 parent 16762ac commit ef00726

8 files changed

Lines changed: 174 additions & 23 deletions

File tree

Cargo.lock

Lines changed: 14 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ resolver = "2"
66
homepage = "https://github.com/loro-dev/columnar"
77
repository = "https://github.com/loro-dev/columnar"
88

9+
[workspace.dependencies]
10+
serde = { version = "^1" }
11+
912
# Added profile settings from fuzz/Cargo.toml
1013
[profile.release]
1114
debug = 1

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ For more detailed introduction, please refer to this `Notion` link: [Serde-Colum
88

99
![Image](https://github.com/user-attachments/assets/48475c7d-61c8-4903-892d-70d702137dba)
1010

11-
## 🚧 This crate is in progress and not stable, should not be used in production environments
12-
1311
## Features 🚀
1412

1513
`serde_columnar` comes with several remarkable features:

columnar/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ repository = "https://github.com/loro-dev/columnar"
1010
keywords = ["columnar", "column-oriented", "compression", "serde", "compatible"]
1111

1212
[dependencies]
13-
serde = { version = "1.0" }
13+
serde = { workspace = true }
1414
serde_columnar_derive = { path = "../columnar_derive", version = "0.3.6" }
1515
postcard = { version = "^1.1.0", features = ["alloc"] }
1616
thiserror = "1.0"
1717
lazy_static = { version = "1.4", optional = true }
1818
bincode = { version = "1.3.3", optional = true }
1919
itertools = "^0.11.0"
20-
flate2 = { version = "1.0", optional = true }
20+
flate2 = { version = "^1.1", optional = true }
2121

2222
[dev-dependencies]
23-
serde = { version = "1.0.188", features = ["derive"] }
23+
serde = { workspace = true, features = ["derive"] }
2424
criterion = "0.5.1"
2525
serde_json = "1.0"
2626
insta = { version = "1.31.0", features = ["yaml"] }

columnar/src/__serde_utils.rs

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
use serde::{
2+
de::{Error, Unexpected, Visitor},
3+
Deserializer,
4+
};
5+
use std::borrow::Cow;
6+
7+
pub fn borrow_cow_str<'de: 'a, 'a, D, R>(deserializer: D) -> Result<R, D::Error>
8+
where
9+
D: Deserializer<'de>,
10+
R: From<Cow<'a, str>>,
11+
{
12+
struct CowStrVisitor;
13+
14+
impl<'a> Visitor<'a> for CowStrVisitor {
15+
type Value = Cow<'a, str>;
16+
17+
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
18+
formatter.write_str("a string")
19+
}
20+
21+
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
22+
where
23+
E: Error,
24+
{
25+
Ok(Cow::Owned(v.to_owned()))
26+
}
27+
28+
fn visit_borrowed_str<E>(self, v: &'a str) -> Result<Self::Value, E>
29+
where
30+
E: Error,
31+
{
32+
Ok(Cow::Borrowed(v))
33+
}
34+
35+
fn visit_string<E>(self, v: String) -> Result<Self::Value, E>
36+
where
37+
E: Error,
38+
{
39+
Ok(Cow::Owned(v))
40+
}
41+
42+
fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E>
43+
where
44+
E: Error,
45+
{
46+
match str::from_utf8(v) {
47+
Ok(s) => Ok(Cow::Owned(s.to_owned())),
48+
Err(_) => Err(Error::invalid_value(Unexpected::Bytes(v), &self)),
49+
}
50+
}
51+
52+
fn visit_borrowed_bytes<E>(self, v: &'a [u8]) -> Result<Self::Value, E>
53+
where
54+
E: Error,
55+
{
56+
match str::from_utf8(v) {
57+
Ok(s) => Ok(Cow::Borrowed(s)),
58+
Err(_) => Err(Error::invalid_value(Unexpected::Bytes(v), &self)),
59+
}
60+
}
61+
62+
fn visit_byte_buf<E>(self, v: Vec<u8>) -> Result<Self::Value, E>
63+
where
64+
E: Error,
65+
{
66+
match String::from_utf8(v) {
67+
Ok(s) => Ok(Cow::Owned(s)),
68+
Err(e) => Err(Error::invalid_value(
69+
Unexpected::Bytes(&e.into_bytes()),
70+
&self,
71+
)),
72+
}
73+
}
74+
}
75+
76+
deserializer.deserialize_str(CowStrVisitor).map(From::from)
77+
}
78+
79+
pub fn borrow_cow_bytes<'de: 'a, 'a, D, R>(deserializer: D) -> Result<R, D::Error>
80+
where
81+
D: Deserializer<'de>,
82+
R: From<Cow<'a, [u8]>>,
83+
{
84+
struct CowBytesVisitor;
85+
86+
impl<'a> Visitor<'a> for CowBytesVisitor {
87+
type Value = Cow<'a, [u8]>;
88+
89+
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
90+
formatter.write_str("a byte array")
91+
}
92+
93+
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
94+
where
95+
E: Error,
96+
{
97+
Ok(Cow::Owned(v.as_bytes().to_vec()))
98+
}
99+
100+
fn visit_borrowed_str<E>(self, v: &'a str) -> Result<Self::Value, E>
101+
where
102+
E: Error,
103+
{
104+
Ok(Cow::Borrowed(v.as_bytes()))
105+
}
106+
107+
fn visit_string<E>(self, v: String) -> Result<Self::Value, E>
108+
where
109+
E: Error,
110+
{
111+
Ok(Cow::Owned(v.into_bytes()))
112+
}
113+
114+
fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E>
115+
where
116+
E: Error,
117+
{
118+
Ok(Cow::Owned(v.to_vec()))
119+
}
120+
121+
fn visit_borrowed_bytes<E>(self, v: &'a [u8]) -> Result<Self::Value, E>
122+
where
123+
E: Error,
124+
{
125+
Ok(Cow::Borrowed(v))
126+
}
127+
128+
fn visit_byte_buf<E>(self, v: Vec<u8>) -> Result<Self::Value, E>
129+
where
130+
E: Error,
131+
{
132+
Ok(Cow::Owned(v))
133+
}
134+
}
135+
136+
deserializer
137+
.deserialize_bytes(CowBytesVisitor)
138+
.map(From::from)
139+
}

columnar/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ pub use wrap::{ColumnarMap, ColumnarVec};
100100

101101
pub use postcard::Error as PostcardError;
102102
pub use serde_columnar_derive::*;
103+
pub mod __serde_utils;
103104

104105
#[cfg(feature = "bench")]
105106
extern crate lazy_static;

columnar_derive/src/serde/de.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl DeFieldAttrs {
7373
quote::quote!(
7474
let #field_name = {
7575
#wrapper
76-
::serde::__private::Option::map(
76+
std::option::Option::map(
7777
::serde::de::SeqAccess::next_element::<#wrapper_ty>(&mut seq)?,
7878
|__wrap| __wrap.value).ok_or_else(|| __A::Error::custom("DeserializeUnexpectedEnd"))?
7979
};
@@ -118,9 +118,9 @@ impl DeFieldAttrs {
118118
segments: Punctuated::new(),
119119
};
120120
let span = Span::call_site();
121-
path.segments.push(Ident::new("serde", span).into());
122-
path.segments.push(Ident::new("__private", span).into());
123-
path.segments.push(Ident::new("de", span).into());
121+
path.segments
122+
.push(Ident::new("serde_columnar", span).into());
123+
path.segments.push(Ident::new("__serde_utils", span).into());
124124
path.segments
125125
.push(Ident::new("borrow_cow_str", span).into());
126126
let ans = syn::ExprPath {
@@ -135,9 +135,9 @@ impl DeFieldAttrs {
135135
segments: Punctuated::new(),
136136
};
137137
let span = Span::call_site();
138-
path.segments.push(Ident::new("serde", span).into());
139-
path.segments.push(Ident::new("__private", span).into());
140-
path.segments.push(Ident::new("de", span).into());
138+
path.segments
139+
.push(Ident::new("serde_columnar", span).into());
140+
path.segments.push(Ident::new("__serde_utils", span).into());
141141
path.segments
142142
.push(Ident::new("borrow_cow_bytes", span).into());
143143
let ans = syn::ExprPath {
@@ -381,19 +381,19 @@ fn wrap_deserialize_with(
381381
#[doc(hidden)]
382382
struct __DeserializeWith #de_impl_generics #where_clause {
383383
value: #value_ty,
384-
phantom: ::serde::__private::PhantomData<#this_type #ty_generics>,
385-
lifetime: ::serde::__private::PhantomData<&#delife ()>,
384+
phantom: std::marker::PhantomData<#this_type #ty_generics>,
385+
lifetime: std::marker::PhantomData<&#delife ()>,
386386
}
387387

388388
impl #de_impl_generics serde::Deserialize<#delife> for __DeserializeWith #de_ty_generics #where_clause {
389-
fn deserialize<__D>(__deserializer: __D) -> ::serde::__private::Result<Self, __D::Error>
389+
fn deserialize<__D>(__deserializer: __D) -> std::result::Result<Self, __D::Error>
390390
where
391391
__D: serde::Deserializer<#delife>,
392392
{
393-
::serde::__private::Ok(__DeserializeWith {
393+
std::result::Result::Ok(__DeserializeWith {
394394
value: #deserialize_with(__deserializer)?,
395-
phantom: ::serde::__private::PhantomData,
396-
lifetime: ::serde::__private::PhantomData,
395+
phantom: std::marker::PhantomData,
396+
lifetime: std::marker::PhantomData,
397397
})
398398
}
399399
}

fuzz/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cargo-fuzz = true
99

1010
[dependencies]
1111
libfuzzer-sys = "0.4"
12-
serde = { version = "1.0", features = ["derive"] }
12+
serde = { workspace = true, features = ["derive"] }
1313
arbitrary = { version = "1.1.7", features = ["derive"] }
1414
postcard = "^1.0"
1515

0 commit comments

Comments
 (0)