From a76169042fa7ee5a8aa8fdb6151cf2d84a69eea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Sun, 17 Nov 2019 12:30:39 +0100 Subject: [PATCH] Make the serde and zerocopy meilidb-types dependencies optional --- meilidb-types/Cargo.toml | 14 +++++++++++--- meilidb-types/src/lib.rs | 25 +++++++++---------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/meilidb-types/Cargo.toml b/meilidb-types/Cargo.toml index 67764d3c5..a18d42391 100644 --- a/meilidb-types/Cargo.toml +++ b/meilidb-types/Cargo.toml @@ -4,6 +4,14 @@ version = "0.1.0" authors = ["Clément Renault "] edition = "2018" -[dependencies] -serde = { version = "1.0.101", features = ["derive"] } -zerocopy = "0.2.8" +[dependencies.zerocopy] +version = "0.2.8" +optional = true + +[dependencies.serde] +version = "1.0.101" +features = ["derive"] +optional = true + +[features] +default = ["serde", "zerocopy"] diff --git a/meilidb-types/src/lib.rs b/meilidb-types/src/lib.rs index 9a4b9e978..c02281a5f 100644 --- a/meilidb-types/src/lib.rs +++ b/meilidb-types/src/lib.rs @@ -1,24 +1,16 @@ -use serde::{Deserialize, Serialize}; +#[cfg(feature = "zerocopy")] use zerocopy::{AsBytes, FromBytes}; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + /// Represent an internally generated document unique identifier. /// /// It is used to inform the database the document you want to deserialize. /// Helpful for custom ranking. -#[derive( - Debug, - Copy, - Clone, - Eq, - PartialEq, - PartialOrd, - Ord, - Hash, - Serialize, - Deserialize, - AsBytes, - FromBytes, -)] +#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)] +#[cfg_attr(feature = "zerocopy", derive(AsBytes, FromBytes))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[repr(C)] pub struct DocumentId(pub u64); @@ -27,7 +19,8 @@ pub struct DocumentId(pub u64); /// /// This is stored in the map, generated at index time, /// extracted and interpreted at search time. -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, AsBytes, FromBytes)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[cfg_attr(feature = "zerocopy", derive(AsBytes, FromBytes))] #[repr(C)] pub struct DocIndex { /// The document identifier where the word was found.