Skip to content

Commit eae2ff6

Browse files
Chris Frantzcfrantz
Chris Frantz
authored andcommitted
Eliminate use of nightly feature min_specialization.
The `min_specialization` feature is only available in nightly and doesn't seem to be making progress towards becoming a supported language feature. What is necessary to support serde-annotate is to be able to get a reference to the `dyn Annotate` implementation. With `min_specialization`, this was done by implementing a default `Annotate` for all `T: Serialize` and then specialzing `Annotate` on types with specific annotators. This generally worked, but it did cause some problems around `erased_serde::Serialize` as any type information about the type was erased. What is really required to implement annotations is to be able to look up the Annotators for a given type. The serde serializer actually helps with this: The serialize functions for structs and enums accept a `name` parameter which is the typename of the item being serialized. Instead of using `min_specialization`, we build a database mapping typenames to casting functions that can cast a pointer to the appropriate `dyn Annotate` reference. 1. Simplify the `Annotate` trait to only include the format and comment annotations. 2. Update the derive macro to only implement format/comment. Use the `inventory` crate to register the name to annotator-cast functions. 3. Update tests. Signed-off-by: Chris Frantz <frantzcj@gmail.com>
1 parent 975683b commit eae2ff6

20 files changed

+596
-206
lines changed

.bazelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
build --@rules_rust//rust/toolchain/channel=nightly
1+
#build --@rules_rust//rust/toolchain/channel=nightly

Cargo.Bazel.lock

+313-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"checksum": "d25b71cb8422c2cc372f8d16d141b4bde19d8572657286081c22c02b1873bfc4",
2+
"checksum": "79aea2ecf9b57abcd039ca3c4a962efb4bcb38de962fd02e940aae8dd040f0c2",
33
"crates": {
44
"aho-corasick 1.1.3": {
55
"name": "aho-corasick",
@@ -878,6 +878,53 @@
878878
},
879879
"license": "MIT OR Apache-2.0"
880880
},
881+
"erased-serde 0.4.4": {
882+
"name": "erased-serde",
883+
"version": "0.4.4",
884+
"repository": {
885+
"Http": {
886+
"url": "https://static.crates.io/crates/erased-serde/0.4.4/download",
887+
"sha256": "2b73807008a3c7f171cc40312f37d95ef0396e048b5848d775f54b1a4dd4a0d3"
888+
}
889+
},
890+
"targets": [
891+
{
892+
"Library": {
893+
"crate_name": "erased_serde",
894+
"crate_root": "src/lib.rs",
895+
"srcs": [
896+
"**/*.rs"
897+
]
898+
}
899+
}
900+
],
901+
"library_target_name": "erased_serde",
902+
"common_attrs": {
903+
"compile_data_glob": [
904+
"**"
905+
],
906+
"crate_features": {
907+
"common": [
908+
"alloc",
909+
"default",
910+
"std"
911+
],
912+
"selects": {}
913+
},
914+
"deps": {
915+
"common": [
916+
{
917+
"id": "serde 1.0.197",
918+
"target": "serde"
919+
}
920+
],
921+
"selects": {}
922+
},
923+
"edition": "2021",
924+
"version": "0.4.4"
925+
},
926+
"license": "MIT OR Apache-2.0"
927+
},
881928
"generic-array 0.14.7": {
882929
"name": "generic-array",
883930
"version": "0.14.7",
@@ -1094,6 +1141,36 @@
10941141
},
10951142
"license": "Apache-2.0 OR MIT"
10961143
},
1144+
"inventory 0.3.15": {
1145+
"name": "inventory",
1146+
"version": "0.3.15",
1147+
"repository": {
1148+
"Http": {
1149+
"url": "https://static.crates.io/crates/inventory/0.3.15/download",
1150+
"sha256": "f958d3d68f4167080a18141e10381e7634563984a537f2a49a30fd8e53ac5767"
1151+
}
1152+
},
1153+
"targets": [
1154+
{
1155+
"Library": {
1156+
"crate_name": "inventory",
1157+
"crate_root": "src/lib.rs",
1158+
"srcs": [
1159+
"**/*.rs"
1160+
]
1161+
}
1162+
}
1163+
],
1164+
"library_target_name": "inventory",
1165+
"common_attrs": {
1166+
"compile_data_glob": [
1167+
"**"
1168+
],
1169+
"edition": "2021",
1170+
"version": "0.3.15"
1171+
},
1172+
"license": "MIT OR Apache-2.0"
1173+
},
10971174
"itoa 1.0.11": {
10981175
"name": "itoa",
10991176
"version": "1.0.11",
@@ -1620,6 +1697,167 @@
16201697
},
16211698
"license": "MIT OR Apache-2.0"
16221699
},
1700+
"proc-macro-error 1.0.4": {
1701+
"name": "proc-macro-error",
1702+
"version": "1.0.4",
1703+
"repository": {
1704+
"Http": {
1705+
"url": "https://static.crates.io/crates/proc-macro-error/1.0.4/download",
1706+
"sha256": "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
1707+
}
1708+
},
1709+
"targets": [
1710+
{
1711+
"Library": {
1712+
"crate_name": "proc_macro_error",
1713+
"crate_root": "src/lib.rs",
1714+
"srcs": [
1715+
"**/*.rs"
1716+
]
1717+
}
1718+
},
1719+
{
1720+
"BuildScript": {
1721+
"crate_name": "build_script_build",
1722+
"crate_root": "build.rs",
1723+
"srcs": [
1724+
"**/*.rs"
1725+
]
1726+
}
1727+
}
1728+
],
1729+
"library_target_name": "proc_macro_error",
1730+
"common_attrs": {
1731+
"compile_data_glob": [
1732+
"**"
1733+
],
1734+
"crate_features": {
1735+
"common": [
1736+
"default",
1737+
"syn",
1738+
"syn-error"
1739+
],
1740+
"selects": {}
1741+
},
1742+
"deps": {
1743+
"common": [
1744+
{
1745+
"id": "proc-macro-error 1.0.4",
1746+
"target": "build_script_build"
1747+
},
1748+
{
1749+
"id": "proc-macro2 1.0.79",
1750+
"target": "proc_macro2"
1751+
},
1752+
{
1753+
"id": "quote 1.0.35",
1754+
"target": "quote"
1755+
},
1756+
{
1757+
"id": "syn 1.0.109",
1758+
"target": "syn"
1759+
}
1760+
],
1761+
"selects": {}
1762+
},
1763+
"edition": "2018",
1764+
"proc_macro_deps": {
1765+
"common": [
1766+
{
1767+
"id": "proc-macro-error-attr 1.0.4",
1768+
"target": "proc_macro_error_attr"
1769+
}
1770+
],
1771+
"selects": {}
1772+
},
1773+
"version": "1.0.4"
1774+
},
1775+
"build_script_attrs": {
1776+
"data_glob": [
1777+
"**"
1778+
],
1779+
"deps": {
1780+
"common": [
1781+
{
1782+
"id": "version_check 0.9.4",
1783+
"target": "version_check"
1784+
}
1785+
],
1786+
"selects": {}
1787+
}
1788+
},
1789+
"license": "MIT OR Apache-2.0"
1790+
},
1791+
"proc-macro-error-attr 1.0.4": {
1792+
"name": "proc-macro-error-attr",
1793+
"version": "1.0.4",
1794+
"repository": {
1795+
"Http": {
1796+
"url": "https://static.crates.io/crates/proc-macro-error-attr/1.0.4/download",
1797+
"sha256": "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
1798+
}
1799+
},
1800+
"targets": [
1801+
{
1802+
"ProcMacro": {
1803+
"crate_name": "proc_macro_error_attr",
1804+
"crate_root": "src/lib.rs",
1805+
"srcs": [
1806+
"**/*.rs"
1807+
]
1808+
}
1809+
},
1810+
{
1811+
"BuildScript": {
1812+
"crate_name": "build_script_build",
1813+
"crate_root": "build.rs",
1814+
"srcs": [
1815+
"**/*.rs"
1816+
]
1817+
}
1818+
}
1819+
],
1820+
"library_target_name": "proc_macro_error_attr",
1821+
"common_attrs": {
1822+
"compile_data_glob": [
1823+
"**"
1824+
],
1825+
"deps": {
1826+
"common": [
1827+
{
1828+
"id": "proc-macro-error-attr 1.0.4",
1829+
"target": "build_script_build"
1830+
},
1831+
{
1832+
"id": "proc-macro2 1.0.79",
1833+
"target": "proc_macro2"
1834+
},
1835+
{
1836+
"id": "quote 1.0.35",
1837+
"target": "quote"
1838+
}
1839+
],
1840+
"selects": {}
1841+
},
1842+
"edition": "2018",
1843+
"version": "1.0.4"
1844+
},
1845+
"build_script_attrs": {
1846+
"data_glob": [
1847+
"**"
1848+
],
1849+
"deps": {
1850+
"common": [
1851+
{
1852+
"id": "version_check 0.9.4",
1853+
"target": "version_check"
1854+
}
1855+
],
1856+
"selects": {}
1857+
}
1858+
},
1859+
"license": "MIT OR Apache-2.0"
1860+
},
16231861
"proc-macro2 1.0.79": {
16241862
"name": "proc-macro2",
16251863
"version": "1.0.79",
@@ -1988,6 +2226,7 @@
19882226
],
19892227
"crate_features": {
19902228
"common": [
2229+
"alloc",
19912230
"default",
19922231
"derive",
19932232
"serde_derive",
@@ -2049,6 +2288,14 @@
20492288
"id": "anstyle 1.0.6",
20502289
"target": "anstyle"
20512290
},
2291+
{
2292+
"id": "erased-serde 0.4.4",
2293+
"target": "erased_serde"
2294+
},
2295+
{
2296+
"id": "inventory 0.3.15",
2297+
"target": "inventory"
2298+
},
20522299
{
20532300
"id": "num-traits 0.2.18",
20542301
"target": "num_traits"
@@ -2154,6 +2401,10 @@
21542401
],
21552402
"deps": {
21562403
"common": [
2404+
{
2405+
"id": "proc-macro-error 1.0.4",
2406+
"target": "proc_macro_error"
2407+
},
21572408
{
21582409
"id": "proc-macro2 1.0.79",
21592410
"target": "proc_macro2"
@@ -2476,6 +2727,67 @@
24762727
},
24772728
"license": "MIT"
24782729
},
2730+
"syn 1.0.109": {
2731+
"name": "syn",
2732+
"version": "1.0.109",
2733+
"repository": {
2734+
"Http": {
2735+
"url": "https://static.crates.io/crates/syn/1.0.109/download",
2736+
"sha256": "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
2737+
}
2738+
},
2739+
"targets": [
2740+
{
2741+
"Library": {
2742+
"crate_name": "syn",
2743+
"crate_root": "src/lib.rs",
2744+
"srcs": [
2745+
"**/*.rs"
2746+
]
2747+
}
2748+
},
2749+
{
2750+
"BuildScript": {
2751+
"crate_name": "build_script_build",
2752+
"crate_root": "build.rs",
2753+
"srcs": [
2754+
"**/*.rs"
2755+
]
2756+
}
2757+
}
2758+
],
2759+
"library_target_name": "syn",
2760+
"common_attrs": {
2761+
"compile_data_glob": [
2762+
"**"
2763+
],
2764+
"deps": {
2765+
"common": [
2766+
{
2767+
"id": "proc-macro2 1.0.79",
2768+
"target": "proc_macro2"
2769+
},
2770+
{
2771+
"id": "syn 1.0.109",
2772+
"target": "build_script_build"
2773+
},
2774+
{
2775+
"id": "unicode-ident 1.0.12",
2776+
"target": "unicode_ident"
2777+
}
2778+
],
2779+
"selects": {}
2780+
},
2781+
"edition": "2018",
2782+
"version": "1.0.109"
2783+
},
2784+
"build_script_attrs": {
2785+
"data_glob": [
2786+
"**"
2787+
]
2788+
},
2789+
"license": "MIT OR Apache-2.0"
2790+
},
24792791
"syn 2.0.55": {
24802792
"name": "syn",
24812793
"version": "2.0.55",

0 commit comments

Comments
 (0)