Skip to content

Commit 79f3484

Browse files
authored
Merge pull request #2964 from dtolnay/serdecoredoc
Update documentation of serde_core
2 parents 66c5d2b + ac8b7ea commit 79f3484

5 files changed

Lines changed: 25 additions & 171 deletions

File tree

serde/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ alloc = ["serde_core/alloc"]
7171
# Be sure that this is what you want before enabling this feature.
7272
rc = ["serde_core/rc"]
7373

74-
# Provide impls for Result<T, E>. Enabling these impls allows for serialization
75-
# and deserialization of Result types, which may be useful in certain contexts
76-
# but could lead to confusion if ? or unwrap are overused.
74+
# Provide impls for Result<T, E>. Convenient in some contexts but can lead to
75+
# confusion if ? or unwrap are used incautiously.
7776
result = ["serde_core/result"]

serde_core/Cargo.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ version = "1.0.219"
44
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
55
build = "build.rs"
66
categories = ["encoding", "no-std", "no-std::no-alloc"]
7-
description = "Core functionalities and abstractions for the Serde serialization/deserialization framework"
7+
description = "Serde traits only, with no support for derive -- use the `serde` crate instead"
88
documentation = "https://docs.rs/serde_core"
99
edition = "2021"
1010
homepage = "https://serde.rs"
1111
keywords = ["serde", "serialization", "no_std"]
1212
license = "MIT OR Apache-2.0"
13-
readme = "crates-io.md"
1413
repository = "https://github.com/serde-rs/serde"
1514
rust-version = "1.56"
1615

@@ -56,7 +55,6 @@ alloc = []
5655
# Be sure that this is what you want before enabling this feature.
5756
rc = []
5857

59-
# Provide impls for Result<T, E>. Enabling these impls allows for serialization
60-
# and deserialization of Result types, which may be useful in certain contexts
61-
# but could lead to confusion if ? or unwrap are overused.
58+
# Provide impls for Result<T, E>. Convenient in some contexts but can lead to
59+
# confusion if ? or unwrap are used incautiously.
6260
result = []

serde_core/README.md

Lines changed: 9 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,12 @@
1-
# Serde &emsp; [![Build Status]][actions] [![Latest Version]][crates.io] [![serde msrv]][Rust 1.56] [![serde_derive msrv]][Rust 1.61]
1+
The `serde_core` crate contains Serde's trait definitions with **no support for
2+
#\[derive()\]**.
23

3-
[Build Status]: https://img.shields.io/github/actions/workflow/status/serde-rs/serde/ci.yml?branch=master
4-
[actions]: https://github.com/serde-rs/serde/actions?query=branch%3Amaster
5-
[Latest Version]: https://img.shields.io/crates/v/serde.svg
6-
[crates.io]: https://crates.io/crates/serde
7-
[serde msrv]: https://img.shields.io/crates/msrv/serde.svg?label=serde%20msrv&color=lightgray
8-
[serde_derive msrv]: https://img.shields.io/crates/msrv/serde_derive.svg?label=serde_derive%20msrv&color=lightgray
9-
[Rust 1.56]: https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html
10-
[Rust 1.61]: https://blog.rust-lang.org/2022/05/19/Rust-1.61.0.html
4+
In crates that derive an implementation of `Serialize` or `Deserialize`, you
5+
must depend on the [`serde`] crate, not `serde_core`.
116

12-
**Serde is a framework for *ser*ializing and *de*serializing Rust data structures efficiently and generically.**
7+
In crates that handwrite implementations of Serde traits, or only use them as
8+
trait bounds, depending on `serde_core` is permitted. But `serde` re-exports all
9+
of these traits and can be used for this use case too. If in doubt, disregard
10+
`serde_core` and always use `serde`.
1311

14-
---
15-
16-
You may be looking for:
17-
18-
- [An overview of Serde](https://serde.rs/)
19-
- [Data formats supported by Serde](https://serde.rs/#data-formats)
20-
- [Setting up `#[derive(Serialize, Deserialize)]`](https://serde.rs/derive.html)
21-
- [Examples](https://serde.rs/examples.html)
22-
- [API documentation](https://docs.rs/serde)
23-
- [Release notes](https://github.com/serde-rs/serde/releases)
24-
25-
## Serde in action
26-
27-
<details>
28-
<summary>
29-
Click to show Cargo.toml.
30-
<a href="https://play.rust-lang.org/?edition=2021&gist=72755f28f99afc95e01d63174b28c1f5" target="_blank">Run this code in the playground.</a>
31-
</summary>
32-
33-
```toml
34-
[dependencies]
35-
36-
# The core APIs, including the Serialize and Deserialize traits. Always
37-
# required when using Serde. The "derive" feature is only required when
38-
# using #[derive(Serialize, Deserialize)] to make Serde work with structs
39-
# and enums defined in your crate.
40-
serde = { version = "1.0", features = ["derive"] }
41-
42-
# Each data format lives in its own crate; the sample code below uses JSON
43-
# but you may be using a different one.
44-
serde_json = "1.0"
45-
```
46-
47-
</details>
48-
<p></p>
49-
50-
```rust
51-
use serde::{Deserialize, Serialize};
52-
53-
#[derive(Serialize, Deserialize, Debug)]
54-
struct Point {
55-
x: i32,
56-
y: i32,
57-
}
58-
59-
fn main() {
60-
let point = Point { x: 1, y: 2 };
61-
62-
// Convert the Point to a JSON string.
63-
let serialized = serde_json::to_string(&point).unwrap();
64-
65-
// Prints serialized = {"x":1,"y":2}
66-
println!("serialized = {}", serialized);
67-
68-
// Convert the JSON string back to a Point.
69-
let deserialized: Point = serde_json::from_str(&serialized).unwrap();
70-
71-
// Prints deserialized = Point { x: 1, y: 2 }
72-
println!("deserialized = {:?}", deserialized);
73-
}
74-
```
75-
76-
## Getting help
77-
78-
Serde is one of the most widely used Rust libraries so any place that Rustaceans
79-
congregate will be able to help you out. For chat, consider trying the
80-
[#rust-questions] or [#rust-beginners] channels of the unofficial community
81-
Discord (invite: <https://discord.gg/rust-lang-community>), the [#rust-usage] or
82-
[#beginners] channels of the official Rust Project Discord (invite:
83-
<https://discord.gg/rust-lang>), or the [#general][zulip] stream in Zulip. For
84-
asynchronous, consider the [\[rust\] tag on StackOverflow][stackoverflow], the
85-
[/r/rust] subreddit which has a pinned weekly easy questions post, or the Rust
86-
[Discourse forum][discourse]. It's acceptable to file a support issue in this
87-
repo but they tend not to get as many eyes as any of the above and may get
88-
closed without a response after some time.
89-
90-
[#rust-questions]: https://discord.com/channels/273534239310479360/274215136414400513
91-
[#rust-beginners]: https://discord.com/channels/273534239310479360/273541522815713281
92-
[#rust-usage]: https://discord.com/channels/442252698964721669/443150878111694848
93-
[#beginners]: https://discord.com/channels/442252698964721669/448238009733742612
94-
[zulip]: https://rust-lang.zulipchat.com/#narrow/stream/122651-general
95-
[stackoverflow]: https://stackoverflow.com/questions/tagged/rust
96-
[/r/rust]: https://www.reddit.com/r/rust
97-
[discourse]: https://users.rust-lang.org
98-
99-
<br>
100-
101-
#### License
102-
103-
<sup>
104-
Licensed under either of <a href="LICENSE-APACHE">Apache License, Version
105-
2.0</a> or <a href="LICENSE-MIT">MIT license</a> at your option.
106-
</sup>
107-
108-
<br>
109-
110-
<sub>
111-
Unless you explicitly state otherwise, any contribution intentionally submitted
112-
for inclusion in Serde by you, as defined in the Apache-2.0 license, shall be
113-
dual licensed as above, without any additional terms or conditions.
114-
</sub>
12+
[`serde`]: https://crates.io/crates/serde

serde_core/crates-io.md

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

serde_core/src/lib.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
//! # Serde Core
2-
//!
31
//! Serde is a framework for ***ser***ializing and ***de***serializing Rust data
42
//! structures efficiently and generically.
53
//!
6-
//! `serde_core` provides essential traits and functions that form the backbone of Serde. It is intended for use by data format implementations;
7-
//! while it is possible to depend on `serde` crate in a crate that implements a data format,
8-
//! doing so means that the build of data format crate cannot start until serde_derive is done building (if that feature is enabled).
9-
//! Thus, implementing a data format in terms of serde_core and not of serde should improve compile times of users of your data format.
4+
//! The `serde_core` crate contains Serde's trait definitions with **no support
5+
//! for #\[derive()\]**.
106
//!
11-
//! Alternatively, as an user of data formats you could use `serde_core` instead of `serde` if you do not intend to enable derive feature on `serde`.
7+
//! In crates that derive an implementation of `Serialize` or `Deserialize`, you
8+
//! must depend on the [`serde`] crate, not `serde_core`.
129
//!
13-
//! If you're still unsure which crate to use, favor `serde` for the most straightforward experience.
14-
//! For more detailed information and usage examples, refer to Serde's documentation at <https://serde.rs/>.
10+
//! In crates that handwrite implementations of Serde traits, or only use them
11+
//! as trait bounds, depending on `serde_core` is permitted. But `serde`
12+
//! re-exports all of these traits and can be used for this use case too. If in
13+
//! doubt, disregard `serde_core` and always use `serde`.
1514
//!
15+
//! [`serde`]: https://crates.io/crates/serde
16+
1617
////////////////////////////////////////////////////////////////////////////////
1718

1819
// Serde types in rustdoc of other crates get linked to here.
19-
#![doc(html_root_url = "https://docs.rs/serde_core/1.0.219")]
20+
#![doc(html_root_url = "https://docs.rs/serde/1.0.219")]
2021
// Support using Serde without the standard library!
2122
#![cfg_attr(not(feature = "std"), no_std)]
2223
// Show which crate feature enables conditionally compiled APIs in documentation.

0 commit comments

Comments
 (0)