@@ -58,12 +58,15 @@ type DefaultAllocatedField = String;
58
58
///
59
59
/// # Optimising bulk responses
60
60
///
61
- /// The `BulkResponse` type has a few generic parameters for the index, type and id fields.
61
+ /// If you're only interested in bulk operations that failed, see [`BulkErrorsResponse`](struct.BulkErrorsResponse.html).
62
+ /// It can avoid allocating bulk operation responses that will never be processed.
63
+ ///
64
+ /// Both the `BulkResponse` and `BulkErrorsResponse` types have generic parameters for the index, type and id fields.
62
65
/// If your bulk operations have a small set of possible values for these fields you can avoid
63
66
/// allocating `String`s on the heap by using an alternative type, like an `enum`.
64
67
///
65
68
/// In the example below, we expect all bulk operations to use either a type called `mytypea` or `mytypeb`
66
- /// and an index called `myindex :
69
+ /// and an index called `myindex` :
67
70
///
68
71
/// ```no_run
69
72
/// # extern crate serde;
@@ -74,22 +77,23 @@ type DefaultAllocatedField = String;
74
77
/// # fn main() {
75
78
/// # fn do_request() -> BulkResponse<Index, Type> { unimplemented!() }
76
79
/// #[derive(Deserialize)]
80
+ /// #[serde(rename_all = "lowercase")]
77
81
/// enum Index {
78
- /// #[serde(rename = "myindex")]
79
82
/// MyIndex,
80
83
/// }
81
84
///
82
85
/// #[derive(Deserialize)]
86
+ /// #[serde(rename_all = "lowercase")]
83
87
/// enum Type {
84
- /// #[serde(rename = "mytypea")]
85
88
/// MyTypeA,
86
- /// #[serde(rename = "mytypeb")]
87
89
/// MyTypeB,
88
90
/// }
89
91
///
90
92
/// let bulk: BulkResponse<Index, Type> = do_request();
91
93
/// # }
92
- /// ```
94
+ /// ```
95
+ ///
96
+ /// Also see the [`string-cache`](https://github.com/servo/string-cache) crate as an alternative to using `String`s and `enum`s.
93
97
#[ derive( Deserialize , Debug , Clone ) ]
94
98
pub struct BulkResponse < TIndex = DefaultAllocatedField , TType = DefaultAllocatedField , TId = DefaultAllocatedField > {
95
99
pub took : u64 ,
@@ -134,41 +138,6 @@ impl<TIndex, TType, TId> BulkResponse<TIndex, TType, TId> {
134
138
/// }
135
139
/// # }
136
140
/// ```
137
- ///
138
- /// # Optimising bulk responses
139
- ///
140
- /// The `BulkErrorsResponse` type has a few generic parameters for the index, type and id fields.
141
- /// If your bulk operations have a small set of possible values for these fields you can avoid
142
- /// allocating `String`s on the heap by using an alternative type, like an `enum`.
143
- ///
144
- /// In the example below, we expect all bulk operations to use either a type called `mytypea` or `mytypeb`
145
- /// and an index called `myindex :
146
- ///
147
- /// ```no_run
148
- /// # extern crate serde;
149
- /// # #[macro_use] extern crate serde_derive;
150
- /// # extern crate serde_json;
151
- /// # extern crate elastic_responses;
152
- /// # use elastic_responses::*;
153
- /// # fn main() {
154
- /// # fn do_request() -> BulkErrorsResponse<Index, Type> { unimplemented!() }
155
- /// #[derive(Deserialize)]
156
- /// enum Index {
157
- /// #[serde(rename = "myindex")]
158
- /// MyIndex,
159
- /// }
160
- ///
161
- /// #[derive(Deserialize)]
162
- /// enum Type {
163
- /// #[serde(rename = "mytypea")]
164
- /// MyTypeA,
165
- /// #[serde(rename = "mytypeb")]
166
- /// MyTypeB,
167
- /// }
168
- ///
169
- /// let bulk: BulkErrorsResponse<Index, Type> = do_request();
170
- /// # }
171
- /// ```
172
141
#[ derive( Deserialize , Debug , Clone ) ]
173
142
#[ serde( bound( deserialize = "TIndex: Deserialize<'de>, TType: Deserialize<'de>, TId: Deserialize<'de>" ) ) ]
174
143
pub struct BulkErrorsResponse < TIndex = DefaultAllocatedField , TType = DefaultAllocatedField , TId = DefaultAllocatedField > {
0 commit comments