Trait elastic::types::prelude::PropertiesMapping
[−]
[src]
pub trait PropertiesMapping { fn props_len() -> usize; fn serialize_props<S>(
state: &mut S
) -> Result<(), <S as SerializeStruct>::Error>
where
S: SerializeStruct; }
Serialisation for the mapping of object properties.
This trait is designed to be auto-derived, so it expects you to be familiar with how serde
works.
Examples
Say we have a mappable type with 3 fields called MyType
and a mapping type called MyTypeMapping
:
struct MyType { pub my_date: Date<DefaultDateFormat>, pub my_string: String, pub my_num: i32 } #[derive(Default)] struct MyTypeMapping;
To serialise the mapping of each of MyType
s fields, we implement PropertiesMapping
for MyTypeMapping
,
and use serde
to serialise the mapping types for each field.
impl PropertiesMapping for MyTypeMapping { fn props_len() -> usize { 3 } fn serialize_props<S>(state: &mut S) -> Result<(), S::Error> where S: SerializeStruct { try!(field_ser(state, "my_date", Date::<DefaultDateFormat>::mapping())); try!(field_ser(state, "my_string", String::mapping())); try!(field_ser(state, "my_num", i32::mapping())); Ok(()) } }
It's easy to get an instance of the mapping for a given type by calling the static mapping
function.
This trait is automatically implemented for you when you #[derive(ElasticType)]
.
Required Methods
fn props_len() -> usize
The number of mapped property fields for this type.
This number should be the same as the number of fields being serialised by serialize_props
.
fn serialize_props<S>(
state: &mut S
) -> Result<(), <S as SerializeStruct>::Error> where
S: SerializeStruct,
state: &mut S
) -> Result<(), <S as SerializeStruct>::Error> where
S: SerializeStruct,
Serialisation for the mapped property fields on this type.
You can use the field_ser
function to simplify serde
calls.
Implementors
impl PropertiesMapping for ValueDocumentMapping