mysql_common/value/json/
mod.rs

1// Copyright (c) 2017 Anatoly Ikorsky
2//
3// Licensed under the Apache License, Version 2.0
4// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
5// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. All files in the project carrying such notice may not be copied,
7// modified, or distributed except according to those terms.
8
9use serde::{Deserialize, Serialize};
10
11pub mod serde_integration;
12
13/// Use it to pass `T: Serialize` as JSON to a prepared statement.
14///
15/// ```ignore
16/// #[derive(Serialize)]
17/// struct SerializableStruct {
18///     // ...
19/// }
20///
21/// conn.prep_exec("INSERT INTO table (json_column) VALUES (?)",
22///                (Serialized(SerializableStruct),));
23/// ```
24#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash, Serialize)]
25#[serde(transparent)]
26pub struct Serialized<T>(pub T);
27
28/// Use it to parse `T: Deserialize` from `Value`.
29///
30/// ```ignore
31/// #[derive(Deserialize)]
32/// struct DeserializableStruct {
33///     // ...
34/// }
35/// // ...
36/// let (Deserialized(val),): (Deserialized<DeserializableStruct>,)
37///     = from_row(row_with_single_json_column);
38/// ```
39#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash, Deserialize)]
40#[serde(transparent)]
41pub struct Deserialized<T>(pub T);