warning: variables can be used directly in the `format!` string --> serde_derive/src/internals/attr.rs:546:36 | 546 | meta.error(format_args!("unknown serde container attribute `{}`", path)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args = note: `-W clippy::uninlined-format-args` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::uninlined_format_args)]` help: change this to | 546 - meta.error(format_args!("unknown serde container attribute `{}`", path)) 546 + meta.error(format_args!("unknown serde container attribute `{path}`")) | warning: variables can be used directly in the `format!` string --> serde_derive/src/internals/attr.rs:940:36 | 940 | meta.error(format_args!("unknown serde variant attribute `{}`", path)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 940 - meta.error(format_args!("unknown serde variant attribute `{}`", path)) 940 + meta.error(format_args!("unknown serde variant attribute `{path}`")) | warning: variables can be used directly in the `format!` string --> serde_derive/src/internals/attr.rs:1095:33 | 1095 | ... format!("field `{}` does not have lifetime {}", ident, lifetime); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 1095 - format!("field `{}` does not have lifetime {}", ident, lifetime); 1095 + format!("field `{ident}` does not have lifetime {lifetime}"); | warning: variables can be used directly in the `format!` string --> serde_derive/src/internals/attr.rs:1196:47 | 1196 | ... let msg = format!( | _________________________________^ 1197 | | ... "field `{}` does not have lifetime {}", 1198 | | ... ident, lifetime, 1199 | | ... ); | |_______________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args warning: variables can be used directly in the `format!` string --> serde_derive/src/internals/attr.rs:1222:36 | 1222 | meta.error(format_args!("unknown serde field attribute `{}`", path)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 1222 - meta.error(format_args!("unknown serde field attribute `{}`", path)) 1222 + meta.error(format_args!("unknown serde field attribute `{path}`")) | warning: variables can be used directly in the `format!` string --> serde_derive/src/internals/attr.rs:1415:39 | 1415 | return Err(meta.error(format_args!( | _______________________________________^ 1416 | | "malformed {0} attribute, expected `{0}(serialize = ..., deserialize = ...)`", 1417 | | attr_name, 1418 | | ))); | |_________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args warning: variables can be used directly in the `format!` string --> serde_derive/src/internals/attr.rs:1482:17 | 1482 | format!("unexpected suffix `{}` on string literal", suffix), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 1482 - format!("unexpected suffix `{}` on string literal", suffix), 1482 + format!("unexpected suffix `{suffix}` on string literal"), | warning: variables can be used directly in the `format!` string --> serde_derive/src/internals/attr.rs:1489:13 | 1489 | / format!( 1490 | | "expected serde {} attribute to be a string: `{} = \"...\"`", 1491 | | attr_name, meta_item_name 1492 | | ), | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args warning: variables can be used directly in the `format!` string --> serde_derive/src/internals/attr.rs:1604:21 | 1604 | format!("duplicate borrowed lifetime `{}`", lifetime), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 1604 - format!("duplicate borrowed lifetime `{}`", lifetime), 1604 + format!("duplicate borrowed lifetime `{lifetime}`"), | warning: variables can be used directly in the `format!` string --> serde_derive/src/internals/attr.rs:1778:19 | 1778 | let msg = format!("field `{}` has no lifetimes to borrow", name); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 1778 - let msg = format!("field `{}` has no lifetimes to borrow", name); 1778 + let msg = format!("field `{name}` has no lifetimes to borrow"); | warning: variables can be used directly in the `format!` string --> serde_derive/src/internals/check.rs:41:29 | 41 | ... format!("field must have #[serde(default)] because previous field {} has #[serde(default)]", first), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 41 - format!("field must have #[serde(default)] because previous field {} has #[serde(default)]", first), 41 + format!("field must have #[serde(default)] because previous field {first} has #[serde(default)]"), | warning: variables can be used directly in the `format!` string --> serde_derive/src/internals/check.rs:314:13 | 314 | format!("variant field name `{}` conflicts with internal tag", tag), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 314 - format!("variant field name `{}` conflicts with internal tag", tag), 314 + format!("variant field name `{tag}` conflicts with internal tag"), | warning: variables can be used directly in the `format!` string --> serde_derive/src/internals/check.rs:361:13 | 361 | / format!( 362 | | "enum tags `{}` for type and content conflict with each other", 363 | | type_tag 364 | | ), | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args warning: variables can be used directly in the `format!` string --> serde_derive/src/internals/check.rs:450:33 | 450 | Member::Named(ident) => format!("`{}`", ident), | ^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 450 - Member::Named(ident) => format!("`{}`", ident), 450 + Member::Named(ident) => format!("`{ident}`"), | warning: variables can be used directly in the `format!` string --> serde_derive/src/de.rs:697:9 | 697 | format!("{} with 1 element", expecting) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 697 - format!("{} with 1 element", expecting) 697 + format!("{expecting} with 1 element") | warning: variables can be used directly in the `format!` string --> serde_derive/src/de.rs:699:9 | 699 | format!("{} with {} elements", expecting, deserialized_count) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 699 - format!("{} with {} elements", expecting, deserialized_count) 699 + format!("{expecting} with {deserialized_count} elements") | warning: variables can be used directly in the `format!` string --> serde_derive/src/de.rs:1442:21 | 1442 | let expecting = format!("adjacently tagged enum {}", rust_name); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 1442 - let expecting = format!("adjacently tagged enum {}", rust_name); 1442 + let expecting = format!("adjacently tagged enum {rust_name}"); | warning: variables can be used directly in the `format!` string --> serde_derive/src/de.rs:2842:17 | 2842 | Ident::new(&format!("__field{}", i), Span::call_site()) | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 2842 - Ident::new(&format!("__field{}", i), Span::call_site()) 2842 + Ident::new(&format!("__field{i}"), Span::call_site()) | warning: variables can be used directly in the `format!` string --> serde_derive/src/ser.rs:457:42 | 457 | .map(|i| Ident::new(&format!("__field{}", i), Span::call_site())); | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 457 - .map(|i| Ident::new(&format!("__field{}", i), Span::call_site())); 457 + .map(|i| Ident::new(&format!("__field{i}"), Span::call_site())); | warning: variables can be used directly in the `format!` string --> serde_derive/src/ser.rs:714:48 | 714 | .map(|i| Member::Named(Ident::new(&format!("__field{}", i), Span::call_site()))) | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 714 - .map(|i| Member::Named(Ident::new(&format!("__field{}", i), Span::call_site()))) 714 + .map(|i| Member::Named(Ident::new(&format!("__field{i}"), Span::call_site()))) | warning: variables can be used directly in the `format!` string --> serde_derive/src/ser.rs:832:46 | 832 | let field_expr = Ident::new(&format!("__field{}", i), Span::call_site()); | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 832 - let field_expr = Ident::new(&format!("__field{}", i), Span::call_site()); 832 + let field_expr = Ident::new(&format!("__field{i}"), Span::call_site()); | warning: variables can be used directly in the `format!` string --> serde_derive/src/ser.rs:1062:38 | 1062 | let id = Ident::new(&format!("__field{}", i), Span::call_site()); | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 1062 - let id = Ident::new(&format!("__field{}", i), Span::call_site()); 1062 + let id = Ident::new(&format!("__field{i}"), Span::call_site()); |
Serde

Serde is a framework for serializing and deserializing Rust data structures efficiently and generically.
You may be looking for:
- An overview of Serde
- Data formats supported by Serde
- Setting up
#[derive(Serialize, Deserialize)]
- Examples
- API documentation
- Release notes
Serde in action
Click to show Cargo.toml. Run this code in the playground.
[dependencies]
# The core APIs, including the Serialize and Deserialize traits. Always
# required when using Serde. The "derive" feature is only required when
# using #[derive(Serialize, Deserialize)] to make Serde work with structs
# and enums defined in your crate.
serde = { version = "1.0", features = ["derive"] }
# Each data format lives in its own crate; the sample code below uses JSON
# but you may be using a different one.
serde_json = "1.0"
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
struct Point {
x: i32,
y: i32,
}
fn main() {
let point = Point { x: 1, y: 2 };
// Convert the Point to a JSON string.
let serialized = serde_json::to_string(&point).unwrap();
// Prints serialized = {"x":1,"y":2}
println!("serialized = {}", serialized);
// Convert the JSON string back to a Point.
let deserialized: Point = serde_json::from_str(&serialized).unwrap();
// Prints deserialized = Point { x: 1, y: 2 }
println!("deserialized = {:?}", deserialized);
}
Getting help
Serde is one of the most widely used Rust libraries so any place that Rustaceans congregate will be able to help you out. For chat, consider trying the #rust-questions or #rust-beginners channels of the unofficial community Discord (invite: https://discord.gg/rust-lang-community), the #rust-usage or #beginners channels of the official Rust Project Discord (invite: https://discord.gg/rust-lang), or the #general stream in Zulip. For asynchronous, consider the [rust] tag on StackOverflow, the /r/rust subreddit which has a pinned weekly easy questions post, or the Rust Discourse forum. It's acceptable to file a support issue in this repo but they tend not to get as many eyes as any of the above and may get closed without a response after some time.
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Serde by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.