]>
Commit | Line | Data |
---|---|---|
8faf50e0 XL |
1 | /// Conditional compilation depending on whether Serde is built with support for |
2 | /// 128-bit integers. | |
3 | /// | |
e1599b0c XL |
4 | /// Data formats that wish to support Rust compiler versions older than 1.26 |
5 | /// (or targets that lack 128-bit integers) may place the i128 / u128 methods | |
6 | /// of their Serializer and Deserializer behind this macro. | |
8faf50e0 | 7 | /// |
e1599b0c XL |
8 | /// Data formats that require a minimum Rust compiler version of at least 1.26, |
9 | /// or do not target platforms that lack 128-bit integers, do not need to | |
10 | /// bother with this macro and may assume support for 128-bit integers. | |
8faf50e0 | 11 | /// |
dc9dc135 | 12 | /// ```edition2018 |
5869c6ff | 13 | /// # use serde::__private::doc::Error; |
8faf50e0 XL |
14 | /// # |
15 | /// # struct MySerializer; | |
dc9dc135 XL |
16 | /// # |
17 | /// use serde::{serde_if_integer128, Serializer}; | |
8faf50e0 XL |
18 | /// |
19 | /// impl Serializer for MySerializer { | |
20 | /// type Ok = (); | |
21 | /// type Error = Error; | |
22 | /// | |
23 | /// fn serialize_i64(self, v: i64) -> Result<Self::Ok, Self::Error> { | |
24 | /// /* ... */ | |
25 | /// # unimplemented!() | |
26 | /// } | |
27 | /// | |
28 | /// /* ... */ | |
29 | /// | |
30 | /// serde_if_integer128! { | |
31 | /// fn serialize_i128(self, v: i128) -> Result<Self::Ok, Self::Error> { | |
32 | /// /* ... */ | |
33 | /// # unimplemented!() | |
34 | /// } | |
35 | /// | |
36 | /// fn serialize_u128(self, v: u128) -> Result<Self::Ok, Self::Error> { | |
37 | /// /* ... */ | |
38 | /// # unimplemented!() | |
39 | /// } | |
40 | /// } | |
41 | /// # | |
dc9dc135 | 42 | /// # serde::__serialize_unimplemented! { |
8faf50e0 XL |
43 | /// # bool i8 i16 i32 u8 u16 u32 u64 f32 f64 char str bytes none some |
44 | /// # unit unit_struct unit_variant newtype_struct newtype_variant seq | |
45 | /// # tuple tuple_struct tuple_variant map struct struct_variant | |
46 | /// # } | |
47 | /// } | |
8faf50e0 XL |
48 | /// ``` |
49 | /// | |
50 | /// When Serde is built with support for 128-bit integers, this macro expands | |
51 | /// transparently into just the input tokens. | |
52 | /// | |
dc9dc135 | 53 | /// ```edition2018 |
8faf50e0 XL |
54 | /// macro_rules! serde_if_integer128 { |
55 | /// ($($tt:tt)*) => { | |
56 | /// $($tt)* | |
57 | /// }; | |
58 | /// } | |
59 | /// ``` | |
60 | /// | |
61 | /// When built without support for 128-bit integers, this macro expands to | |
62 | /// nothing. | |
63 | /// | |
dc9dc135 | 64 | /// ```edition2018 |
8faf50e0 XL |
65 | /// macro_rules! serde_if_integer128 { |
66 | /// ($($tt:tt)*) => {}; | |
67 | /// } | |
68 | /// ``` | |
69 | #[cfg(integer128)] | |
70 | #[macro_export] | |
71 | macro_rules! serde_if_integer128 { | |
72 | ($($tt:tt)*) => { | |
73 | $($tt)* | |
74 | }; | |
75 | } | |
76 | ||
77 | #[cfg(not(integer128))] | |
78 | #[macro_export] | |
79 | #[doc(hidden)] | |
80 | macro_rules! serde_if_integer128 { | |
81 | ($($tt:tt)*) => {}; | |
82 | } |