David Tolnay
dda070f45c
Fix borrow error on pre-NLL compilers
error[E0506]: cannot assign to `missing_content` because it is borrowed --> serde_derive/src/de.rs:1414:9 | 1388 | .filter_map(|(i, variant)| { | -------------- borrow of `missing_content` occurs here ... 1414 | / missing_content = quote! { 1415 | | match __field { 1416 | | #(#missing_content_arms)* 1417 | | #missing_content_fallthrough 1418 | | } 1419 | | }; | |_________^ assignment to borrowed `missing_content` occurs here error[E0502]: cannot borrow `missing_content_fallthrough` as immutable because it is also borrowed as mutable --> serde_derive/src/de.rs:1414:27 | 1388 | .filter_map(|(i, variant)| { | -------------- mutable borrow occurs here ... 1404 | missing_content_fallthrough = quote!(_ => #missing_content); | --------------------------- previous borrow occurs due to use of `missing_content_fallthrough` in closure ... 1414 | missing_content = quote! { | ___________________________^ 1415 | | match __field { 1416 | | #(#missing_content_arms)* 1417 | | #missing_content_fallthrough 1418 | | } 1419 | | }; | |_________^ immutable borrow occurs here ... 1622 | } | - mutable borrow ends here | = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
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::{Serialize, Deserialize};
#[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 developers live in the #serde channel on irc.mozilla.org
. The
#rust channel is also a good resource with generally faster response time but
less specific knowledge about Serde. If IRC is not your thing or you don't get a
good response, we are happy to respond to GitHub issues as well.
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.
Description
Languages
Rust
100%