mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-25 19:45:05 +08:00
Add Serialize impl
This commit is contained in:
parent
75969f9f68
commit
6688604a93
@ -105,7 +105,7 @@ impl HeedAuthStore {
|
|||||||
|
|
||||||
let mut actions = HashSet::new();
|
let mut actions = HashSet::new();
|
||||||
for action in &key.actions {
|
for action in &key.actions {
|
||||||
match action {
|
match *action {
|
||||||
Action::All => actions.extend(enum_iterator::all::<Action>()),
|
Action::All => actions.extend(enum_iterator::all::<Action>()),
|
||||||
Action::DocumentsAll => {
|
Action::DocumentsAll => {
|
||||||
actions.extend(
|
actions.extend(
|
||||||
|
@ -4,8 +4,9 @@ use std::str::FromStr;
|
|||||||
|
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
use deserr::{take_cf_content, DeserializeError, Deserr, MergeWithError, ValuePointerRef};
|
use deserr::{take_cf_content, DeserializeError, Deserr, MergeWithError, ValuePointerRef};
|
||||||
|
use enum_iterator::Sequence;
|
||||||
use milli::update::Setting;
|
use milli::update::Setting;
|
||||||
use serde::{Deserialize, Deserializer, Serialize};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
use time::format_description::well_known::Rfc3339;
|
use time::format_description::well_known::Rfc3339;
|
||||||
use time::macros::{format_description, time};
|
use time::macros::{format_description, time};
|
||||||
use time::{Date, OffsetDateTime, PrimitiveDateTime};
|
use time::{Date, OffsetDateTime, PrimitiveDateTime};
|
||||||
@ -180,7 +181,7 @@ fn parse_expiration_date(
|
|||||||
}
|
}
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
#[derive(Copy, Clone, Serialize, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct Action: u8 {
|
pub struct Action: u8 {
|
||||||
const All = 0;
|
const All = 0;
|
||||||
@ -361,6 +362,20 @@ impl<'de> Deserialize<'de> for Action {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Serialize for Action {
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
Self::SERIALIZATION_MAP
|
||||||
|
.iter()
|
||||||
|
.find(|(_, action)| self == action)
|
||||||
|
.map(|(serialized, _)| serializer.serialize_str(serialized))
|
||||||
|
// should always be found, so unwrap is safe to use
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub mod actions {
|
pub mod actions {
|
||||||
use super::Action as A;
|
use super::Action as A;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user