Skip to content

Commit eebeb50

Browse files
committed
Drop partial ser/de support
1 parent 5056415 commit eebeb50

File tree

11 files changed

+3
-249
lines changed

11 files changed

+3
-249
lines changed

Cargo.Bazel.lock

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"checksum": "fb64f56ffe49bf513c5c452aa608fee4b8bb1d9c1c9448e0a898baa7b7db8294",
2+
"checksum": "30966b16f4d4befb4a3d4e8958940a723b5bb9d99bb61475a460e972be60014c",
33
"crates": {
44
"aho-corasick 1.1.3": {
55
"name": "aho-corasick",
@@ -2193,10 +2193,6 @@
21932193
{
21942194
"id": "thiserror 1.0.58",
21952195
"target": "thiserror"
2196-
},
2197-
{
2198-
"id": "typeid 1.0.3",
2199-
"target": "typeid"
22002196
}
22012197
],
22022198
"selects": {}

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

serde_annotate/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ rust_library(
5050
"@crate_index//:scopeguard",
5151
"@crate_index//:serde",
5252
"@crate_index//:thiserror",
53-
"@crate_index//:typeid",
5453
],
5554
)
5655

serde_annotate/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ anstyle = "1.0"
88
thiserror = "1.0"
99
num-traits = "0.2.15"
1010
serde = "1.0"
11-
typeid = "1"
1211
once_cell = "1.12"
1312
serde_annotate_derive = {path = "../serde_annotate_derive"}
1413
pest = "2.2"

serde_annotate/src/annotate.rs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
use std::fmt;
2-
3-
use crate::{AnnotatedSerializer, Document, Error};
4-
51
/// Specifies the formatting options to use when serializing.
62
pub enum Format {
73
/// Format a string in block/multiline style.
@@ -31,40 +27,9 @@ pub enum MemberId<'a> {
3127
Variant,
3228
}
3329

34-
/// Trait indicating a type can be serialized by `AnnotatedSerialize`.
35-
///
36-
/// This is specialized version of `Serialize` trait that operates only on `AnnotatedSerializer`,
37-
/// so it is dyn-safe.
38-
pub trait AnnotateSerialize {
39-
fn annotated_serialize(&self, serializer: &mut AnnotatedSerializer) -> Result<Document, Error>;
40-
}
41-
42-
impl<T: serde::Serialize + ?Sized> AnnotateSerialize for T {
43-
fn annotated_serialize(&self, serializer: &mut AnnotatedSerializer) -> Result<Document, Error> {
44-
self.serialize(serializer)
45-
}
46-
}
47-
48-
impl serde::Serialize for dyn AnnotateSerialize {
49-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
50-
where
51-
S: serde::Serializer,
52-
{
53-
AnnotatedSerializer::specialize(serializer, |serializer| {
54-
self.annotated_serialize(serializer)
55-
})
56-
}
57-
}
58-
59-
impl fmt::Debug for dyn AnnotateSerialize {
60-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61-
write!(f, "dyn AnnotateSerialize({:p})", self)
62-
}
63-
}
64-
6530
/// Trait implemented on structs to inform the serializer about formatting
6631
/// options and comments.
67-
pub trait Annotate: AnnotateSerialize {
32+
pub trait Annotate {
6833
fn format(&self, variant: Option<&str>, field: &MemberId) -> Option<Format>;
6934
fn comment(&self, variant: Option<&str>, field: &MemberId) -> Option<String>;
7035
}

serde_annotate/src/de.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Deserializer for serde-annotate `Document`s.
22

3-
use std::mem::ManuallyDrop;
4-
53
use serde::de::{
64
self, DeserializeOwned, DeserializeSeed, EnumAccess, IntoDeserializer, MapAccess, SeqAccess,
75
VariantAccess, Visitor,
@@ -71,32 +69,6 @@ impl<'de> Deserializer<'de> {
7169
doc: doc.as_value()?,
7270
})
7371
}
74-
75-
/// Try to convert a generic `Serializer` into `Self`.
76-
pub fn try_specialize<D: serde::Deserializer<'de>, T>(
77-
deserializer: D,
78-
ok: impl FnOnce(&mut Self) -> Result<T>,
79-
err: impl FnOnce(D) -> Result<T, D::Error>,
80-
) -> Result<T, D::Error> {
81-
if typeid::of::<D>() == typeid::of::<&mut Self>() {
82-
// SAFETY: If `deserializer` is the correct type, then we can transmute the
83-
// reference into `&mut Deserializer`.
84-
//
85-
// For the lifetime, we observe that the lifetime on `ok` works for any lifetime.
86-
// So the exact lifetime on the `&mut` would not matter for the soundness.
87-
// We observe that `D: Deserializer<'de>`, so we can infer that `'d` is correct for
88-
// the lifetime parameter.
89-
let deserializer: &mut Self =
90-
unsafe { std::mem::transmute_copy(&ManuallyDrop::new(deserializer)) };
91-
92-
let r = ok(deserializer);
93-
94-
// SAFETY: Similarly, we can transmute the return value.
95-
unsafe { std::mem::transmute_copy(&ManuallyDrop::new(r)) }
96-
} else {
97-
err(deserializer)
98-
}
99-
}
10072
}
10173

10274
/// Parses and deserializes a `str` into a `T`. The parser is

serde_annotate/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ mod error;
77
mod hexdump;
88
mod integer;
99
mod json;
10-
mod partial;
1110
mod relax;
1211
mod ser;
1312
mod yaml;
1413

15-
pub use annotate::{Annotate, AnnotateSerialize};
14+
pub use annotate::Annotate;
1615
pub use color::ColorProfile;
1716
pub use de::{from_str, Deserialize, Deserializer};
1817
pub use doc_iter::DocPath;

serde_annotate/src/partial.rs

Lines changed: 0 additions & 36 deletions
This file was deleted.

serde_annotate/src/ser.rs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::cell::Cell;
2-
use std::mem::ManuallyDrop;
32

43
use serde::ser;
54

@@ -39,30 +38,6 @@ impl AnnotatedSerializer {
3938
}
4039
}
4140

42-
/// Try to convert a generic `Serializer` into `Self`.
43-
pub fn try_specialize<S: serde::Serializer>(
44-
serializer: S,
45-
ok: impl FnOnce(&mut AnnotatedSerializer) -> Result<Document, Error>,
46-
err: impl FnOnce(S) -> Result<S::Ok, S::Error>,
47-
) -> Result<S::Ok, S::Error> {
48-
if typeid::of::<S>() == typeid::of::<&mut AnnotatedSerializer>() {
49-
// SAFETY: If `serializer` is the correct type, then we can transmute the
50-
// reference into `&mut AnnotatedSerializer`.
51-
//
52-
// For the lifetime, we observe that the lifetime on `ok` works for any lifetime.
53-
// So the exact lifetime would not matter for the soundness.
54-
let serializer: &mut AnnotatedSerializer =
55-
unsafe { std::mem::transmute_copy(&ManuallyDrop::new(serializer)) };
56-
57-
let r = ok(serializer);
58-
59-
// SAFETY: Similarly, we can transmute the return value.
60-
unsafe { std::mem::transmute_copy(&ManuallyDrop::new(r)) }
61-
} else {
62-
err(serializer)
63-
}
64-
}
65-
6641
/// Provide an annotator to inform how to annotate the serialization of the current object.
6742
pub fn with<T>(value: Option<&dyn Annotate>, f: impl FnOnce(Option<&dyn Annotate>) -> T) -> T {
6843
ANNOTATE.with(|annotate| {
@@ -77,19 +52,6 @@ impl AnnotatedSerializer {
7752
})
7853
}
7954

80-
/// Convert a generic `Serializer` into `Self`, panic on failure.
81-
pub fn specialize<S: serde::Serializer>(
82-
serializer: S,
83-
f: impl FnOnce(&mut AnnotatedSerializer) -> Result<Document, Error>,
84-
) -> Result<S::Ok, S::Error> {
85-
Self::try_specialize(serializer, f, |_| {
86-
panic!(
87-
"Expected to be called by AnnotatedSerializer, not {:?}",
88-
std::any::type_name::<S>(),
89-
);
90-
})
91-
}
92-
9355
fn with_base(&self, b: Base) -> Self {
9456
let mut x = self.clone();
9557
x.base = b;

serde_annotate/tests/BUILD.bazel

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,3 @@ rust_test(
4949
"@crate_index//:serde",
5050
],
5151
)
52-
53-
rust_test(
54-
name = "test_partial",
55-
srcs = ["test_partial.rs"],
56-
edition = "2021",
57-
proc_macro_deps = [
58-
"//serde_annotate_derive",
59-
],
60-
deps = [
61-
"//serde_annotate",
62-
"@crate_index//:anyhow",
63-
"@crate_index//:serde",
64-
"@crate_index//:serde_json",
65-
],
66-
)

0 commit comments

Comments
 (0)