You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: types/src/lib.rs
+65-12Lines changed: 65 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,67 @@
1
1
//! Elasticsearch Core Types
2
2
//!
3
3
//! A high-level implementation of the core types in Elasticsearch documents.
4
-
//!
4
+
//!
5
5
//! Types within this crate are self-contained and handle their own serialisation/deserialisation requirements.
6
6
//! Each type also supplies a `struct` for its [Put Mapping API](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html) properties.
7
-
//!
7
+
//!
8
+
//! # Types
9
+
//!
10
+
//! Types in Elasticsearch are a combination of _source_ and _mapping_.
11
+
//! The source is the data (like `42` or `"my string"`) and the mapping is metadata about how to
12
+
//! interpret and use the data (like the format of a date string).
13
+
//!
14
+
//! The approach `elastic_types` takes to types is to bundle the mapping up as a _Zero Sized Type_.
15
+
//! This mapping type is then bound to a field as a generic parameter. For example:
16
+
//!
17
+
//! ```text
18
+
//! ElasticString<DefaultStringMapping>
19
+
//! ```
20
+
//!
21
+
//! The source is a `string` and the mapping is `DefaultStringMapping`.
22
+
//!
23
+
//! All Elasticsearch types implement the base `ElasticType<M: ElasticTypeMapping<F>, F>` trait
24
+
//! where `M` is the mapping and `F` is a type-specific format.
25
+
//!
26
+
//! The following table illustrates the types provided by `elastic_types`:
27
+
//!
28
+
//! Elasticsearch Type | Rust Primitive (Default) | Crate | Rust Type (Custom) | Format Type
Copy file name to clipboardExpand all lines: types/src/mapping.rs
+37-36Lines changed: 37 additions & 36 deletions
Original file line number
Diff line number
Diff line change
@@ -1,38 +1,38 @@
1
1
//! Base requirements for type mappings.
2
-
//!
2
+
//!
3
3
//! There are two kinds of types we can map in Elasticsearch; `field`/`data` types and `user-defined` types.
4
4
//! Either kind of type must implement `ElasticType`, which captures the mapping and possible formatting requirements as generic parameters.
5
5
//! Most of the work lives in the `ElasticTypeMapping`, which holds the serialisation requirements to convert a Rust type into an Elasticsearch mapping.
6
6
//! User-defined types must also implement `ElasticUserTypeMapping`, which maps the fields of a struct as properties, and treats the type as `nested` when used as a field itself.
7
-
//!
7
+
//!
8
8
//! # Notes
9
-
//!
9
+
//!
10
10
//! Currently, there's a lot of ceremony around the type mapping. The reason for doing this with types instead of simple hashmaps is to try and capture type mapping using types themselves.
11
11
//! This means more boilerplate while certain Rust features haven't landed yet ([specialisation](https://github.com/rust-lang/rust/issues/31844) and [negative trait bounds](https://github.com/rust-lang/rfcs/issues/1053)),
12
12
//! but it also constrains the shapes that Elasticsearch types can take by using the Rust type system. That seems like a nice property.
13
-
//!
13
+
//!
14
14
//! The mapping serialisation in general tries to limit allocations wherever possible, but more can be done to clean this up.
0 commit comments