Skip to content

Commit f89cdc7

Browse files
authored
Typesense derive enhancements (#59)
* feat: Typesense derive enhancements & fix partial struct derive generate nested Option<> * test for nested struct derive * nested struct derive integration test * revert: partial struct derive nested `Option` is neccesary for updating a field to `null` & added test * integration test coverage for `locale` and `optional` attributes * derive optimization: avoid runtime `.flatten().collect()` for collection fields
1 parent 2caf0f1 commit f89cdc7

15 files changed

+1624
-161
lines changed

typesense/src/traits/field_type.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::traits::Document;
12
use std::collections::{BTreeMap, HashMap};
23
/// Type for a field. Currently it is a wrapping to a `String` but it could be extended to a enum
34
pub type FieldType = String;
@@ -8,6 +9,19 @@ pub trait ToTypesenseField {
89
/// Static function that should implement the types of the typesense documents.
910
fn to_typesense_type() -> &'static str;
1011
}
12+
/// Generic implementation for any type that is also a Typesense document.
13+
impl<T: Document> ToTypesenseField for T {
14+
fn to_typesense_type() -> &'static str {
15+
"object"
16+
}
17+
}
18+
19+
/// Generic implementation for a Vec of any type that is also a Typesense document.
20+
impl<T: Document> ToTypesenseField for Vec<T> {
21+
fn to_typesense_type() -> &'static str {
22+
"object[]"
23+
}
24+
}
1125

1226
/// macro used internally to add implementations of ToTypesenseField for several rust types.
1327
#[macro_export]

0 commit comments

Comments
 (0)