elasticsearch_dsl/search/sort/
sort_.rs1use super::{FieldSort, GeoDistanceSort, ScriptSort, SortSpecialField};
2use std::borrow::Cow;
3
4#[derive(Clone, PartialEq, Serialize)]
6#[serde(untagged)]
7#[allow(clippy::large_enum_variant)]
8pub enum Sort {
9 SpecialField(SortSpecialField),
11
12 Field(String),
14
15 FieldSort(FieldSort),
17
18 GeoDistanceSort(GeoDistanceSort),
20
21 ScriptSort(ScriptSort),
23}
24
25impl std::fmt::Debug for Sort {
26 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27 match self {
28 Self::SpecialField(sort) => sort.fmt(f),
29 Self::Field(sort) => sort.fmt(f),
30 Self::FieldSort(sort) => sort.fmt(f),
31 Self::GeoDistanceSort(sort) => sort.fmt(f),
32 Self::ScriptSort(sort) => sort.fmt(f),
33 }
34 }
35}
36
37impl From<SortSpecialField> for Sort {
38 fn from(value: SortSpecialField) -> Self {
39 Self::SpecialField(value)
40 }
41}
42
43impl From<&str> for Sort {
44 fn from(value: &str) -> Self {
45 Self::Field(value.to_string())
46 }
47}
48
49impl From<Cow<'_, str>> for Sort {
50 fn from(value: Cow<'_, str>) -> Self {
51 Self::Field(value.to_string())
52 }
53}
54
55impl From<String> for Sort {
56 fn from(value: String) -> Self {
57 Self::Field(value)
58 }
59}
60
61impl From<FieldSort> for Sort {
62 fn from(value: FieldSort) -> Self {
63 Self::FieldSort(value)
64 }
65}
66
67impl From<GeoDistanceSort> for Sort {
68 fn from(value: GeoDistanceSort) -> Self {
69 Self::GeoDistanceSort(value)
70 }
71}
72
73impl From<ScriptSort> for Sort {
74 fn from(value: ScriptSort) -> Self {
75 Self::ScriptSort(value)
76 }
77}
78
79impl IntoIterator for Sort {
80 type Item = Self;
81
82 type IntoIter = std::option::IntoIter<Self::Item>;
83
84 fn into_iter(self) -> Self::IntoIter {
85 Some(self).into_iter()
86 }
87}