From 9b56a434e7fe32ba2157d0b9f725a43c74a3971a Mon Sep 17 00:00:00 2001 From: JMARyA Date: Wed, 28 Aug 2024 08:50:38 +0200 Subject: [PATCH] fix --- src/lib.rs | 2 ++ src/model/mod.rs | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b0f1ee2..bf940e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,8 +3,10 @@ pub use model::historic::Historic; pub use model::reference::*; pub use model::valid::Validate; pub use model::Model; +pub use model::Sort; pub use mongod_derive as derive; pub use mongodb; + #[cfg(feature = "cache")] pub mod cache; #[cfg(feature = "cache")] diff --git a/src/model/mod.rs b/src/model/mod.rs index 7279058..e0b850e 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -354,11 +354,19 @@ pub trait Model: /// "sort_key": Sort::Ascending /// })).await.unwrap(); /// ``` -#[repr(i8)] -#[derive(serde::Serialize, serde::Deserialize, Debug)] +#[derive(Debug)] pub enum Sort { /// Sort in ascending order - Ascending = 1, + Ascending, /// Sort in descending order - Descending = -1, + Descending, +} + +impl Into for Sort { + fn into(self) -> mongodb::bson::Bson { + match self { + Sort::Ascending => mongodb::bson::bson!(1), + Sort::Descending => mongodb::bson::bson!(-1), + } + } }