1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! Cast one struct into another
//!
//! ```rust
//! use serde::{Serialize, Deserialize};
//! use serde_cast::serde_cast;
//!
//! #[derive(Serialize)]
//! struct A {
//! field: String,
//! }
//!
//! #[derive(Deserialize)]
//! struct B {
//! field: String,
//! }
//!
//! let a = A { field: "This was a mistake".to_string() };
//! let b: B = serde_cast!(&a);
//!
//! assert_eq!(a.field, b.field);
//! ```
pub use serde as __ser;
pub use ron as __de;
/// The macro.
///
/// ```rust
/// use serde::{Serialize, Deserialize};
/// use serde_cast::serde_cast;
///
/// #[derive(Serialize)]
/// struct A {
/// field: String,
/// }
///
/// #[derive(Deserialize)]
/// struct B {
/// field: String,
/// }
///
/// let a = A { field: "This was a mistake".to_string() };
/// let b: B = serde_cast!(&a);
///
/// assert_eq!(a.field, b.field);
/// ```
///
/// Casting A to B if fields of A and B don't exactly match is undefined behavior