├── CNAME ├── .ignore ├── _skeptic ├── .gitignore ├── tests │ └── skeptic.rs ├── build.rs └── Cargo.toml ├── .gitignore ├── img ├── run.png ├── runtab.png ├── rustdoc.svg └── github.svg ├── package.json ├── gitbook ├── images │ ├── favicon.ico │ └── apple-touch-icon-precomposed-152.png ├── fonts │ └── fontawesome │ │ ├── FontAwesome.otf │ │ ├── fontawesome-webfont.eot │ │ ├── fontawesome-webfont.ttf │ │ ├── fontawesome-webfont.woff │ │ └── fontawesome-webfont.woff2 ├── gitbook-plugin-sane-sidebar │ └── plugin.js ├── gitbook-plugin-checklist │ └── checklist.css ├── gitbook-plugin-codeblock-rust │ └── block.css ├── gitbook-plugin-anchors │ └── plugin.css ├── gitbook-plugin-edit-link │ └── plugin.js ├── gitbook-plugin-ga4 │ └── plugin.js ├── gitbook-plugin-lunr │ ├── search-lunr.js │ └── lunr.min.js ├── gitbook-plugin-highlight │ └── ebook.css └── gitbook-plugin-fontsettings │ ├── fontsettings.js │ └── website.css ├── redirects.json ├── codegen.html ├── borrow.html ├── _src ├── _layouts │ ├── website │ │ ├── header.html │ │ ├── languages.html │ │ ├── layout.html │ │ ├── summary.html │ │ └── page.html │ └── layout.html ├── attr-rename.md ├── enum-number.md ├── styles │ └── website.css ├── json.md ├── help.md ├── attributes.md ├── data-format.md ├── custom-serialization.md ├── transcode.md ├── attr-default.md ├── SUMMARY.md ├── attr-skip-serializing.md ├── no-std.md ├── conventions.md ├── custom-date-format.md ├── convert-error.md ├── feature-flags.md ├── ignored-any.md ├── examples.md ├── attr-flatten.md ├── attr-bound.md ├── deserialize-map.md ├── stream-array.md ├── derive.md ├── error-handling.md ├── enum-representations.md ├── variant-attrs.md ├── unit-testing.md ├── deserialize-struct.md ├── field-attrs.md ├── string-or-struct.md ├── impl-deserialize.md ├── README.md ├── remote-derive.md ├── data-model.md ├── container-attrs.md ├── impl-serialize.md └── lifetimes.md ├── book.json ├── CONTRIBUTING.md ├── styles └── website.css └── .github └── workflows └── ci.yml /CNAME: -------------------------------------------------------------------------------- 1 | serde.rs 2 | -------------------------------------------------------------------------------- /.ignore: -------------------------------------------------------------------------------- 1 | search_index.json 2 | -------------------------------------------------------------------------------- /_skeptic/.gitignore: -------------------------------------------------------------------------------- 1 | /Cargo.lock 2 | /target/ 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /_book/ 2 | /node_modules/ 3 | /package-lock.json 4 | -------------------------------------------------------------------------------- /_skeptic/tests/skeptic.rs: -------------------------------------------------------------------------------- 1 | include!(concat!(env!("OUT_DIR"), "/skeptic-tests.rs")); 2 | -------------------------------------------------------------------------------- /img/run.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serde-rs/serde-rs.github.io/master/img/run.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "gitbook-cli": "^2.3.2" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /img/runtab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serde-rs/serde-rs.github.io/master/img/runtab.png -------------------------------------------------------------------------------- /gitbook/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serde-rs/serde-rs.github.io/master/gitbook/images/favicon.ico -------------------------------------------------------------------------------- /gitbook/fonts/fontawesome/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serde-rs/serde-rs.github.io/master/gitbook/fonts/fontawesome/FontAwesome.otf -------------------------------------------------------------------------------- /_skeptic/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let sources = skeptic::markdown_files_of_directory("../_src"); 3 | skeptic::generate_doc_tests(&sources); 4 | } 5 | -------------------------------------------------------------------------------- /gitbook/fonts/fontawesome/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serde-rs/serde-rs.github.io/master/gitbook/fonts/fontawesome/fontawesome-webfont.eot -------------------------------------------------------------------------------- /gitbook/fonts/fontawesome/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serde-rs/serde-rs.github.io/master/gitbook/fonts/fontawesome/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /gitbook/fonts/fontawesome/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serde-rs/serde-rs.github.io/master/gitbook/fonts/fontawesome/fontawesome-webfont.woff -------------------------------------------------------------------------------- /gitbook/fonts/fontawesome/fontawesome-webfont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serde-rs/serde-rs.github.io/master/gitbook/fonts/fontawesome/fontawesome-webfont.woff2 -------------------------------------------------------------------------------- /gitbook/images/apple-touch-icon-precomposed-152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serde-rs/serde-rs.github.io/master/gitbook/images/apple-touch-icon-precomposed-152.png -------------------------------------------------------------------------------- /gitbook/gitbook-plugin-sane-sidebar/plugin.js: -------------------------------------------------------------------------------- 1 | require(["gitbook", "jQuery"], function(gitbook, $) { 2 | gitbook.events.bind('start', function (e, config) { 3 | if ($(document).width() <= 600) { 4 | gitbook.sidebar.toggle(false, false); 5 | } 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /redirects.json: -------------------------------------------------------------------------------- 1 | { 2 | "redirects": [ 3 | { 4 | "from": "codegen.html", 5 | "to": "derive.html" 6 | }, 7 | { 8 | "from": "borrow.html", 9 | "to": "lifetimes.html#borrowing-data-in-a-derived-impl" 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /codegen.html: -------------------------------------------------------------------------------- 1 |
Click here if you are not redirected
-------------------------------------------------------------------------------- /gitbook/gitbook-plugin-checklist/checklist.css: -------------------------------------------------------------------------------- 1 | .markdown-section ul.checklist { 2 | list-style-type: none; 3 | padding-left: 3em; 4 | } 5 | 6 | .markdown-section ul.checklist li div.checkbox { 7 | width: 0; 8 | height: 0; 9 | position: relative; 10 | top: 0.2em; 11 | } 12 | 13 | .markdown-section ul.checklist li div.checkbox input[type='checkbox'] { 14 | position: absolute; 15 | right: 0.5em; 16 | width: 1.25em; 17 | height: 1.25em; 18 | } 19 | -------------------------------------------------------------------------------- /borrow.html: -------------------------------------------------------------------------------- 1 |Click here if you are not redirected
-------------------------------------------------------------------------------- /gitbook/gitbook-plugin-codeblock-rust/block.css: -------------------------------------------------------------------------------- 1 | .code-filename { 2 | background-color: rgba(0,0,0,0.07); 3 | display: inline-block; 4 | padding: 2px 8px; 5 | font-size: small; 6 | line-height: inherit; 7 | margin-bottom: 0px !important; 8 | } 9 | 10 | .markdown-section pre { 11 | position: relative; 12 | } 13 | 14 | .playground-link { 15 | display: inline-block; 16 | position: absolute; 17 | top: 5px; 18 | right: 5px; 19 | } 20 | 21 | .playground-link:after { 22 | content: 'Run'; 23 | } 24 | -------------------------------------------------------------------------------- /_src/_layouts/website/header.html: -------------------------------------------------------------------------------- 1 | {% block book_header %} 2 | 13 | {% endblock %} 14 | -------------------------------------------------------------------------------- /_skeptic/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "serde-website" 3 | version = "0.0.0" 4 | authors = ["David Tolnay```rust code
14 | block which has a `!PLAYGROUND` on the previous line, the hash on that line
15 | needs to be updated by pasting the new code into play.rust-lang.org, clicking
16 | Share, and grabbing the new hash from the generated "Permalink to the
17 | playground" link.
18 |
--------------------------------------------------------------------------------
/gitbook/gitbook-plugin-anchors/plugin.css:
--------------------------------------------------------------------------------
1 |
2 | a.plugin-anchor {
3 | color: inherit !important;
4 | display: none;
5 | margin-left: -30px;
6 | padding-left: 40px;
7 | cursor: pointer;
8 | position: absolute;
9 | top: 0;
10 | left: 0;
11 | bottom: 0;
12 | }
13 |
14 | a.plugin-anchor i {
15 | margin-left: -30px;
16 | font-size: 15px !important;
17 | }
18 |
19 | h1, h2, h3, h4, h5, h6 {
20 | position: relative;
21 | }
22 |
23 | h1:hover a.plugin-anchor, h2:hover a.plugin-anchor, h3:hover a.plugin-anchor,
24 | h4:hover a.plugin-anchor, h5:hover a.plugin-anchor, h6:hover a.plugin-anchor {
25 | display: inline-block;
26 | }
27 |
28 | .book .book-body .page-wrapper .page-inner section.normal {
29 | overflow: visible;
30 | }
31 |
--------------------------------------------------------------------------------
/img/rustdoc.svg:
--------------------------------------------------------------------------------
1 |
5 |
--------------------------------------------------------------------------------
/gitbook/gitbook-plugin-edit-link/plugin.js:
--------------------------------------------------------------------------------
1 | require(["gitbook", "jQuery"], function(gitbook, $) {
2 | gitbook.events.bind('start', function (e, config) {
3 | var conf = config['edit-link'];
4 | var label = conf.label;
5 | var base = conf.base;
6 | var lang = gitbook.state.innerLanguage;
7 | if (lang) {
8 | // label can be a unique string for multi-languages site
9 | if (typeof label === 'object') label = label[lang];
10 |
11 | lang = lang + '/';
12 | }
13 |
14 | // Add slash at the end if not present
15 | if (base.slice(-1) != "/") {
16 | base = base + "/";
17 | }
18 |
19 | gitbook.toolbar.createButton({
20 | icon: 'fa fa-edit',
21 | text: label,
22 | onClick: function() {
23 | var filepath = gitbook.state.filepath;
24 |
25 | window.open(base + lang + filepath);
26 | }
27 | });
28 | });
29 |
30 | });
--------------------------------------------------------------------------------
/_src/enum-number.md:
--------------------------------------------------------------------------------
1 | # Serialize enum as number
2 |
3 | The [serde\_repr] crate provides alternative derive macros that derive the same
4 | Serialize and Deserialize traits but delegate to the underlying representation
5 | of a C-like enum. This allows C-like enums to be formatted as integers rather
6 | than strings in JSON, for example.
7 |
8 | [serde\_repr]: https://github.com/dtolnay/serde-repr
9 |
10 | ```toml
11 | [dependencies]
12 | serde = "1.0"
13 | serde_json = "1.0"
14 | serde_repr = "0.1"
15 | ```
16 |
17 | ```rust
18 | use serde_repr::*;
19 |
20 | #[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)]
21 | #[repr(u8)]
22 | enum SmallPrime {
23 | Two = 2,
24 | Three = 3,
25 | Five = 5,
26 | Seven = 7,
27 | }
28 |
29 | fn main() {
30 | use SmallPrime::*;
31 | let nums = vec![Two, Three, Five, Seven];
32 |
33 | // Prints [2,3,5,7]
34 | println!("{}", serde_json::to_string(&nums).unwrap());
35 |
36 | assert_eq!(Two, serde_json::from_str("2").unwrap());
37 | }
38 | ```
39 |
--------------------------------------------------------------------------------
/gitbook/gitbook-plugin-ga4/plugin.js:
--------------------------------------------------------------------------------
1 | require(["gitbook"], function(gitbook) {
2 | gitbook.events.bind("start", function(e, config) {
3 | window.dataLayer = window.dataLayer || [];
4 | window.gtag = window.gtag || function() {
5 | window.dataLayer.push(arguments);
6 | };
7 | window.gtag('js', new Date());
8 | window.gtag('config', config.ga4.tag, {
9 | anonymize_ip: config.ga4.anonymize_ip ?? false,
10 | cookie_domain: config.ga4.cookie_domain ?? undefined,
11 | cookie_flags: 'samesite=strict;secure',
12 | });
13 | var script = document.createElement("script");
14 | script.type = "text/javascript";
15 | script.async = true;
16 | script.src = "https://www.googletagmanager.com/gtag/js?id=" + config.ga4.tag;
17 | document.getElementsByTagName("head")[0].appendChild(script);
18 | });
19 | gitbook.events.bind("page.change", function() {
20 | window.gtag('event', 'page_view', {
21 | page_location: window.location.pathname + window.location.search,
22 | });
23 | });
24 | });
25 |
--------------------------------------------------------------------------------
/_src/_layouts/website/layout.html:
--------------------------------------------------------------------------------
1 | {% extends "layout.html" %}
2 |
3 | {% block head %}
4 | {{ super() }}
5 |
6 |
7 |
8 |
9 |
10 |
11 | {% endblock %}
12 |
13 | {% block style %}
14 | {### Include theme css before plugins css ###}
15 |
16 |
17 | {{ super() }}
18 |
19 | {### Custom stylesheets for the book ###}
20 |
21 | {% for type, style in config.styles %}
22 | {% if fileExists(style) and type == "website" %}
23 |
24 | {% endif %}
25 | {% endfor %}
26 | {% endblock %}
27 |
28 | {% block body %}{% endblock %}
29 |
--------------------------------------------------------------------------------
/styles/website.css:
--------------------------------------------------------------------------------
1 | .book-summary ul.summary {
2 | margin: 5px 0 30px 0;
3 | }
4 |
5 | .book-summary ul.summary li.chapter a {
6 | padding: 15px 5px 5px 15px;
7 | }
8 |
9 | .book-summary ul.summary li.chapter ul.articles li.chapter a {
10 | padding: 5px 15px;
11 | }
12 |
13 | .markdown-section pre {
14 | line-height: 1.3;
15 | background: none;
16 | padding: .65em 1em;
17 | border-style: solid;
18 | border-width: 2px 2px 2px 0;
19 | border-color: transparent;
20 | margin: 0 0 .85em 10px;
21 | box-shadow: -10px 0 0 0 rgba(0,0,0,0.1);
22 | }
23 |
24 | .markdown-section pre:hover {
25 | border-color: rgba(0,0,0,0.1);
26 | }
27 |
28 | .book .book-body .page-wrapper .page-inner section.normal pre .hljs-comment,
29 | .book .book-body .page-wrapper .page-inner section.normal code .hljs-comment {
30 | color: #787878;
31 | }
32 |
33 | .code-filename {
34 | background-color: rgba(0,0,0,0.1);
35 | }
36 |
37 | a.plugin-anchor {
38 | color: rgba(0,0,0,0.3) !important;
39 | margin-left: -50px;
40 | padding-left: 52px;
41 | }
42 |
43 | a.plugin-anchor i {
44 | margin-left: -50px;
45 | }
46 |
47 | .indent ~ p {
48 | padding-left: 40px;
49 | }
50 |
--------------------------------------------------------------------------------
/_src/styles/website.css:
--------------------------------------------------------------------------------
1 | .book-summary ul.summary {
2 | margin: 5px 0 30px 0;
3 | }
4 |
5 | .book-summary ul.summary li.chapter a {
6 | padding: 15px 5px 5px 15px;
7 | }
8 |
9 | .book-summary ul.summary li.chapter ul.articles li.chapter a {
10 | padding: 5px 15px;
11 | }
12 |
13 | .markdown-section pre {
14 | line-height: 1.3;
15 | background: none;
16 | padding: .65em 1em;
17 | border-style: solid;
18 | border-width: 2px 2px 2px 0;
19 | border-color: transparent;
20 | margin: 0 0 .85em 10px;
21 | box-shadow: -10px 0 0 0 rgba(0,0,0,0.1);
22 | }
23 |
24 | .markdown-section pre:hover {
25 | border-color: rgba(0,0,0,0.1);
26 | }
27 |
28 | .book .book-body .page-wrapper .page-inner section.normal pre .hljs-comment,
29 | .book .book-body .page-wrapper .page-inner section.normal code .hljs-comment {
30 | color: #787878;
31 | }
32 |
33 | .code-filename {
34 | background-color: rgba(0,0,0,0.1);
35 | }
36 |
37 | a.plugin-anchor {
38 | color: rgba(0,0,0,0.3) !important;
39 | margin-left: -50px;
40 | padding-left: 52px;
41 | }
42 |
43 | a.plugin-anchor i {
44 | margin-left: -50px;
45 | }
46 |
47 | .indent ~ p {
48 | padding-left: 40px;
49 | }
50 |
--------------------------------------------------------------------------------
/_src/json.md:
--------------------------------------------------------------------------------
1 | # Structs and enums in JSON
2 |
3 | A Serde `Serializer` is responsible for selecting the convention by which Rust
4 | structs and enums are represented in that format. Here are the conventions
5 | selected by the [`serde_json`] data format. For consistency, other
6 | human-readable formats are encouraged to develop analogous conventions where
7 | possible.
8 |
9 | [`serde_json`]: https://github.com/serde-rs/json
10 |
11 | ```rust
12 | # #![allow(dead_code, unused_variables)]
13 | #
14 | # fn main() {
15 | #
16 | struct W {
17 | a: i32,
18 | b: i32,
19 | }
20 | let w = W { a: 0, b: 0 }; // Represented as `{"a":0,"b":0}`
21 |
22 | struct X(i32, i32);
23 | let x = X(0, 0); // Represented as `[0,0]`
24 |
25 | struct Y(i32);
26 | let y = Y(0); // Represented as just the inner value `0`
27 |
28 | struct Z;
29 | let z = Z; // Represented as `null`
30 |
31 | enum E {
32 | W { a: i32, b: i32 },
33 | X(i32, i32),
34 | Y(i32),
35 | Z,
36 | }
37 | let w = E::W { a: 0, b: 0 }; // Represented as `{"W":{"a":0,"b":0}}`
38 | let x = E::X(0, 0); // Represented as `{"X":[0,0]}`
39 | let y = E::Y(0); // Represented as `{"Y":0}`
40 | let z = E::Z; // Represented as `"Z"`
41 | #
42 | # }
43 | ```
44 |
--------------------------------------------------------------------------------
/_src/help.md:
--------------------------------------------------------------------------------
1 | # Getting help
2 |
3 | Serde is one of the most widely used Rust libraries so any place that Rustaceans
4 | congregate will be able to help you out. For chat, consider trying the
5 | [#rust-questions] or [#rust-beginners] channels of the unofficial community
6 | Discord (invite: