Skip to content

Switching to mdBook #141

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
_book/
node_modules/
book/
14 changes: 3 additions & 11 deletions _src/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
<span style="float:right">
[![GitHub]][repo]
[![rustdoc]][docs]
[![Latest Version]][crates.io]
<a href="https://github.com/serde-rs/serde" target="_blank"><img src="img/github.svg" alt="GitHub"></a>
<a href="https://docs.serde.rs/serde/" target="_blank"><img src="img/rustdoc.svg" alt="rustdoc"></a>
<a href="https://crates.io/crates/serde" target="_blank"><img src="https://img.shields.io/crates/v/serde.svg?style=social" alt="Latest Version"></a>
</span>

[GitHub]: /img/github.svg
[repo]: https://github.com/serde-rs/serde
[rustdoc]: /img/rustdoc.svg
[docs]: https://docs.serde.rs/serde/
[Latest Version]: https://img.shields.io/crates/v/serde.svg?style=social
[crates.io]: https://crates.io/crates/serde

<div style="clear:both"></div>

# Serde
@@ -107,7 +100,6 @@ types in any of the above formats. For example `String`, `&str`, `usize`,
macro to generate serialization implementations for structs in your own program.
Using the derive macro goes like this:

!PLAYGROUND 72755f28f99afc95e01d63174b28c1f5
```rust
use serde::{Serialize, Deserialize};

1 change: 0 additions & 1 deletion _src/attr-bound.md
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@ As with most heuristics, this is not always right and Serde provides an escape
hatch to replace the automatically generated bound by one written by the
programmer.

!PLAYGROUND d2a50878ab69a5786f5a3a11a9de71ea
```rust
use serde::{de, Deserialize, Deserializer};

1 change: 0 additions & 1 deletion _src/attr-default.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Default value for a field

!PLAYGROUND b238170d32f604295a1110ad912ef3ee
```rust
use serde::Deserialize;

1 change: 0 additions & 1 deletion _src/attr-rename.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Serialize fields as camelCase

!PLAYGROUND b2852ed8e696999ccd9d2ac668b848bf
```rust
use serde::Serialize;

1 change: 0 additions & 1 deletion _src/attr-skip-serializing.md
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@ deserializing (see [Field Attributes: `skip`][attr-skip]). Likewise, use

[attr-skip]: field-attrs.md#skip

!PLAYGROUND b65f4a90bb11285574a1917b0f5e10aa
```rust
use serde::Serialize;

2 changes: 1 addition & 1 deletion _src/conventions.md
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ pluggable pretty-printer trait as [`serde_json::ser::Formatter`].
A basic data format begins like this. The three modules are discussed in more
detail on the following pages.

!FILENAME src/lib.rs
**src/lib.rs**
```rust
# macro_rules! modules {
# (mod de) => {
1 change: 0 additions & 1 deletion _src/custom-date-format.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ This uses the [`chrono`](https://github.com/chronotope/chrono) crate to
serialize and deserialize JSON data containing a custom date format. The `with`
attribute is used to provide the logic for handling the custom representation.

!PLAYGROUND 7185eb211a4822ce97184ae25fedda91
```rust
use chrono::{DateTime, Utc};
use serde::{Serialize, Deserialize};
14 changes: 6 additions & 8 deletions _src/derive.md
Original file line number Diff line number Diff line change
@@ -16,20 +16,19 @@ bounds. On rare occasions, for an especially convoluted type you may need to

These derives require a Rust compiler version 1.31 or newer.

!CHECKLIST
- Add `serde = { version = "1.0", features = ["derive"] }` as a dependency in
- [ ] Add `serde = { version = "1.0", features = ["derive"] }` as a dependency in
Cargo.toml.
- Ensure that all other Serde-based dependencies (for example serde_json) are on
- [ ] Ensure that all other Serde-based dependencies (for example serde_json) are on
a version that is compatible with serde 1.0.
- On structs and enums that you want to serialize, import the derive macro as
- [ ] On structs and enums that you want to serialize, import the derive macro as
`use serde::Serialize;` within the same module and write
`#[derive(Serialize)]` on the struct or enum.
- Similarly import `use serde::Deserialize;` and write `#[derive(Deserialize)]`
- [ ] Similarly import `use serde::Deserialize;` and write `#[derive(Deserialize)]`
on structs and enums that you want to deserialize.

Here is the `Cargo.toml`:

!FILENAME Cargo.toml
**Cargo.toml**
```toml
[package]
name = "my-crate"
@@ -45,8 +44,7 @@ serde_json = "1.0"

Now the `src/main.rs` which uses Serde's custom derives:

!FILENAME src/main.rs
!PLAYGROUND 1dbc76000e9875fac72c2865748842d7
**src/main.rs**
```rust
use serde::{Serialize, Deserialize};

1 change: 0 additions & 1 deletion _src/deserialize-map.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Implement Deserialize for a custom map type

!PLAYGROUND 72f10ca685c08f8afeb618efdabfed6a
```rust
use std::fmt;
use std::marker::PhantomData;
1 change: 0 additions & 1 deletion _src/deserialize-struct.md
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@ names. Instead there is a `Field` enum which is deserialized from a `&str`.
The implementation supports two possible ways that a struct may be represented
by a data format: as a seq like in Bincode, and as a map like in JSON.

!PLAYGROUND 2e212d29e38110fc3d8f22ff920712be
```rust
use std::fmt;

2 changes: 1 addition & 1 deletion _src/enum-number.md
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ serde_json = "1.0"
serde_repr = "0.1"
```

```rust
```rust,noplayground
use serde_repr::*;

#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)]
2 changes: 1 addition & 1 deletion _src/error-handling.md
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ for its error type for the data structure to use in various situations.
[`ser::Error`]: https://docs.serde.rs/serde/ser/trait.Error.html
[data model]: data-model.md

!FILENAME src/error.rs
**src/error.rs**
```rust
# macro_rules! ignore {
# ($($tt:tt)*) => {}
File renamed without changes
File renamed without changes
2 changes: 1 addition & 1 deletion _src/impl-deserializer.md
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ there is no advantage to that.
[Deserializer lifetimes]: lifetimes.md
[Serde's data model]: data-model.md

!FILENAME src/de.rs
**src/de.rs**
```rust
# mod error {
# use std;
2 changes: 1 addition & 1 deletion _src/impl-serializer.md
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ is used.
[`Serializer`]: https://docs.serde.rs/serde/trait.Serializer.html
[Serde data model]: data-model.md

!FILENAME src/ser.rs
**src/ser.rs**
```rust
# mod error {
# pub use serde::de::value::Error;
6 changes: 1 addition & 5 deletions _src/remote-derive.md
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ is that you have to provide a definition of the type for Serde's derive to
process. At compile time, Serde will check that all the fields in the definition
you provided match the fields in the remote type.

!PLAYGROUND 0a344c9dfc4cf965e66125ebdfbc48b8
```rust
// Pretend that this is somebody else's crate, not a module.
mod other_crate {
@@ -70,7 +69,6 @@ there is to it. If the remote type is a struct with one or more private fields,
getters must be provided for the private fields and a conversion must be
provided to construct the remote type.

!PLAYGROUND 02b8513dfb060b6580f998bac5a04a1a
```rust
// Pretend that this is somebody else's crate, not a module.
mod other_crate {
@@ -141,7 +139,7 @@ rules as mentioned. The code ultimately generated by these remote derives are
not `Serialize` and `Deserialize` impls but associated functions with the same
signature.

```rust
```rust,noplayground
# #![allow(dead_code)]
#
# use serde::Deserialize;
@@ -170,7 +168,6 @@ struct DurationDef {
Knowing this, the generated method can be invoked directly by passing a
`Deserializer` implementation.

!PLAYGROUND 29cadbd640a231d5703564a666b0bc85
```rust
# #![allow(dead_code)]
#
@@ -196,7 +193,6 @@ let dur = DurationDef::deserialize(&mut de)?;
Alternatively we can write a top-level newtype wrapper as a private helper for
deserializing the remote type.

!PLAYGROUND 159da6ebf3a3573b8bd7f3bc2246026c
```rust
# #![allow(dead_code)]
#
1 change: 0 additions & 1 deletion _src/stream-array.md
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ without holding the whole array in memory all at once. This approach can be
adapted to handle a variety of other situations in which data needs to be
processed while being deserialized instead of after.

!PLAYGROUND 270186a56b8321704dc45001fdfa3c92
```rust
use serde::{Deserialize, Deserializer};
use serde::de::{self, Visitor, SeqAccess};
2 changes: 1 addition & 1 deletion _src/string-or-struct.md
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ We can use Rust's
[`FromStr`](https://doc.rust-lang.org/std/str/trait.FromStr.html) trait and
Serde's `deserialize_with` attribute to handle this pattern in a general way.

```rust
```rust,noplayground
use std::collections::BTreeMap as Map;
use std::fmt;
use std::marker::PhantomData;
2 changes: 1 addition & 1 deletion _src/transcode.md
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ This example implements the equivalent of Go's
[`json.Compact`](https://golang.org/pkg/encoding/json/#Compact) function which
removes insignificant whitespace from a JSON string in a streaming way.

```rust
```rust,noplayground
use std::io;

fn main() {
2 changes: 1 addition & 1 deletion _src/unit-testing.md
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ test expected failure conditions.
Here is an example from the
[`linked-hash-map`](https://github.com/contain-rs/linked-hash-map) crate.

```rust
```rust,noplayground
# #[allow(unused_imports)]
use linked_hash_map::LinkedHashMap;
#
18 changes: 18 additions & 0 deletions book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[book]
language = "en"
multilingual = false
src = "_src"
title = "Serde"

[rust]
edition = "2018"

[output.html]
git-repository-url = "https://github.com/serde-rs/serde-rs.github.io"
git-repository-icon = "fa-github"
edit-url-template = "https://github.com/serde-rs/serde-rs.github.io/edit/master/{path}"
cname = "serde.rs"

[output.html.redirect]
"codegen.html" = "derive.html"
"borrow.html" = "lifetimes.html#borrowing-data-in-a-derived-impl"