Repository: elastic-rs/elastic (language: rust)

Issue:
error: type `elastic_types::private::impls::DefaultMapping` is private
I have the following struct:

```
#[derive(ElasticType, Serialize, Deserialize)]
pub struct Sample {
    pub labels: HashMap<String, String>,
    pub value: f64,
    pub timestamp: i64,
}
```
I have followed the docs:

Cargo.toml:

```
[dependencies]
elastic = "*"
elastic_derive = "*"
serde_json = "*"
serde = "*"
serde_derive = "*"
```
main.rs:
```
#[macro_use]
extern crate serde_json;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate elastic_derive;
extern crate serde;
extern crate elastic;
```
Any idea what's going on here?
This gives me the following error during compilation:
```
error: type `elastic_types::private::impls::DefaultMapping` is private
  --> src/elastic_adapter/adapter.rs:10:10
   |
10 | #[derive(ElasticType, Serialize, Deserialize)]
   |          ^^^^^^^^^^^

error: aborting due to previous error

error: Could not compile `prom-es-rs`.

To learn more, run the command again with --verbose.
```


Discussion / hints:
Thanks for the report @sevagh! This looks like a bug. Some of the implementation details are purposely leaked in that `elastic::private` module so deriving `ElasticType` can work. It looks like Rust might've got a bit smarter about what's public and what's private.

I'll fix it up later today.

Fix patch:
diff --git a/src/elastic/src/client/mod.rs b/src/elastic/src/client/mod.rs
index 9054c78cce..0babcf007a 100644
--- a/src/elastic/src/client/mod.rs
+++ b/src/elastic/src/client/mod.rs
@@ -459,10 +459,10 @@ For more details see the [`responses`][responses-mod] module.
 [AsyncClientBuilder]: struct.AsyncClientBuilder.html
 [Client.request]: struct.Client.html#method.request
 [Client.search]: struct.Client.html#search-request
-[Client.document_get]: struct.Client.html#get-document
-[Client.document_update]: struct.Client.html#update-document
-[Client.document_delete]: struct.Client.html#delete-document
-[Client.document_index]: struct.Client.html#index-request
+[Client.document_get]: struct.Client.html#get-document-request
+[Client.document_update]: struct.Client.html#update-document-request
+[Client.document_delete]: struct.Client.html#delete-document-request
+[Client.document_index]: struct.Client.html#index-document-request
 [Client.document_put_mapping]: struct.Client.html#method.document_put_mapping
 [Client.index_create]: struct.Client.html#create-index-request
 [Client.index_open]: struct.Client.html#open-index-request
diff --git a/src/elastic/src/client/requests/document_delete.rs b/src/elastic/src/client/requests/document_delete.rs
index 9dfd6743c7..8b6e5f46d3 100644
--- a/src/elastic/src/client/requests/document_delete.rs
+++ b/src/elastic/src/client/requests/document_delete.rs
@@ -38,7 +38,7 @@ pub struct DeleteRequestInner<TDocument> {
 }
 
 /**
-# Delete document
+# Delete document request
 */
 impl<TSender> Client<TSender>
 where
diff --git a/src/elastic/src/client/requests/document_get.rs b/src/elastic/src/client/requests/document_get.rs
index 18cf284520..01c5183594 100644
--- a/src/elastic/src/client/requests/document_get.rs
+++ b/src/elastic/src/client/requests/document_get.rs
@@ -39,7 +39,7 @@ pub struct GetRequestInner<TDocument> {
 }
 
 /**
-# Get document
+# Get document request
 */
 impl<TSender> Client<TSender>
 where
diff --git a/src/elastic/src/client/requests/document_index.rs b/src/elastic/src/client/requests/document_index.rs
index ebc9bc558e..4c296412a6 100644
--- a/src/elastic/src/client/requests/document_index.rs
+++ b/src/elastic/src/client/requests/document_index.rs
@@ -39,7 +39,7 @@ pub struct IndexRequestInner<TDocument> {
 }
 
 /**
-# Index document
+# Index document request
 */
 impl<TSender> Client<TSender>
 where
diff --git a/src/elastic/src/client/requests/document_update.rs b/src/elastic/src/client/requests/document_update.rs
index f2d86eeec6..c460b5c7d8 100644
--- a/src/elastic/src/client/requests/document_update.rs
+++ b/src/elastic/src/client/requests/document_update.rs
@@ -41,7 +41,7 @@ pub struct UpdateRequestInner<TBody> {
 }
 
 /**
-# Update document
+# Update document request
 */
 impl<TSender> Client<TSender>
 where
diff --git a/src/types/src/private/impls.rs b/src/types/src/private/impls.rs
index b89f37ec9b..529bd6d215 100644
--- a/src/types/src/private/impls.rs
+++ b/src/types/src/private/impls.rs
@@ -10,7 +10,7 @@ pub trait DefaultFieldType {}
 
 /** A mapping implementation for a non-core type, or anywhere it's ok for Elasticsearch to infer the mapping at index-time. */
 #[derive(Debug, PartialEq, Default, Clone)]
-struct DefaultMapping;
+pub struct DefaultMapping;
 impl FieldMapping<()> for DefaultMapping {
     type DocumentField = DocumentField<DefaultMapping, ()>;
 }


Test patch:
diff --git a/tests/run/src/document/compile_test.rs b/tests/run/src/document/compile_test.rs
new file mode 100644
index 0000000000..43c138b807
--- /dev/null
+++ b/tests/run/src/document/compile_test.rs
@@ -0,0 +1,12 @@
+/**
+Tests for ensuring documents can be derived.
+*/
+
+use std::collections::HashMap;
+
+#[derive(ElasticType, Serialize, Deserialize)]
+pub struct Sample {
+    pub labels: HashMap<String, String>,
+    pub value: f64,
+    pub timestamp: i64,
+}
diff --git a/tests/run/src/document/mod.rs b/tests/run/src/document/mod.rs
index 1e8f5d2466..ac9af64a90 100644
--- a/tests/run/src/document/mod.rs
+++ b/tests/run/src/document/mod.rs
@@ -1,5 +1,7 @@
 use run_tests::{test, Test};
 
+mod compile_test;
+
 mod simple_index_get;
 mod update_with_doc;
 mod update_with_script;