Skip to content

Commit 3e45db5

Browse files
authored
Merge pull request #38 from KodrAus/chore/docs
Rework bulk docs a bit
2 parents f2ee7c4 + f3a7ebf commit 3e45db5

File tree

1 file changed

+10
-41
lines changed

1 file changed

+10
-41
lines changed

src/bulk.rs

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,15 @@ type DefaultAllocatedField = String;
5858
///
5959
/// # Optimising bulk responses
6060
///
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.
6265
/// If your bulk operations have a small set of possible values for these fields you can avoid
6366
/// allocating `String`s on the heap by using an alternative type, like an `enum`.
6467
///
6568
/// 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`:
6770
///
6871
/// ```no_run
6972
/// # extern crate serde;
@@ -74,22 +77,23 @@ type DefaultAllocatedField = String;
7477
/// # fn main() {
7578
/// # fn do_request() -> BulkResponse<Index, Type> { unimplemented!() }
7679
/// #[derive(Deserialize)]
80+
/// #[serde(rename_all = "lowercase")]
7781
/// enum Index {
78-
/// #[serde(rename = "myindex")]
7982
/// MyIndex,
8083
/// }
8184
///
8285
/// #[derive(Deserialize)]
86+
/// #[serde(rename_all = "lowercase")]
8387
/// enum Type {
84-
/// #[serde(rename = "mytypea")]
8588
/// MyTypeA,
86-
/// #[serde(rename = "mytypeb")]
8789
/// MyTypeB,
8890
/// }
8991
///
9092
/// let bulk: BulkResponse<Index, Type> = do_request();
9193
/// # }
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.
9397
#[derive(Deserialize, Debug, Clone)]
9498
pub struct BulkResponse<TIndex = DefaultAllocatedField, TType = DefaultAllocatedField, TId = DefaultAllocatedField> {
9599
pub took: u64,
@@ -134,41 +138,6 @@ impl<TIndex, TType, TId> BulkResponse<TIndex, TType, TId> {
134138
/// }
135139
/// # }
136140
/// ```
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-
/// ```
172141
#[derive(Deserialize, Debug, Clone)]
173142
#[serde(bound(deserialize = "TIndex: Deserialize<'de>, TType: Deserialize<'de>, TId: Deserialize<'de>"))]
174143
pub struct BulkErrorsResponse<TIndex = DefaultAllocatedField, TType = DefaultAllocatedField, TId = DefaultAllocatedField> {

0 commit comments

Comments
 (0)