Skip to content

Commit 7ab9ef5

Browse files
committed
adding type ellision helper
1 parent 6cae5b7 commit 7ab9ef5

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

types/src/mapping.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,34 @@ use serde;
1818
/// # Links
1919
///
2020
/// - [Elasticsearch docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html)
21-
pub trait ElasticDataType<T: ElasticMapping<F>, F> { }
21+
pub trait ElasticDataType<T: ElasticMapping<F>, F> : TypeEllision { }
22+
23+
#[doc(hidden)]
24+
pub enum TypeEllisionKind {
25+
Explicit,
26+
Ellided
27+
}
28+
#[doc(hidden)]
29+
pub trait TypeEllision {
30+
fn get_ellision() -> TypeEllisionKind {
31+
TypeEllisionKind::Explicit
32+
}
33+
}
2234

2335
/// The base requirements for mapping an Elasticsearch data type.
2436
///
2537
/// Each type has its own implementing structures with extra type-specific mapping parameters.
2638
pub trait ElasticMapping<F = ()>
2739
where Self: Default + serde::Serialize {
28-
/// The serialisation visitor used to inspect this mapping.
40+
#[doc(hidden)]
2941
type Visitor : serde::ser::MapVisitor + Default;
3042

3143
/// An optional associated type that mappings may need.
3244
///
3345
/// For example; the `Format` trait on `DateTime`.
3446
type Format = F;
3547

36-
/// Gets an instance of the `Visitor` for serialisation.
48+
#[doc(hidden)]
3749
fn get_visitor() -> Self::Visitor {
3850
Self::Visitor::default()
3951
}

types/tests/field_mapping.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ fn can_access_mapping_for_auto_impls() {
7373
assert_eq!("object", MappingDispatch::<i32>::map(&ty));
7474
}
7575

76+
#[test]
77+
fn can_access_type_ellision_for_mappings() {
78+
79+
}
80+
7681
#[test]
7782
fn serialise_mapping_null() {
7883
let mapping = NullMapping;

types/tests/type_mapping.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct MyType {
1717
pub num: i32
1818
}
1919

20+
//All this should be derived
2021
impl <'a> ElasticDataType<MyTypeMapping<'a>, ()> for MyType { }
2122

2223
//The mapping for our type
@@ -62,7 +63,7 @@ impl <'a> serde::Serialize for MyTypeMapping<'a> {
6263
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
6364
where S: serde::Serializer
6465
{
65-
serializer.serialize_struct("mapping", MyTypeMappingVisitor::default())
66+
serializer.serialize_struct("properties", MyTypeMappingVisitor::default())
6667
}
6768
}
6869

0 commit comments

Comments
 (0)