git_bug/query/normalize/
mod.rs1use std::fmt::Display;
14
15use super::{Matcher, Query, queryable::Queryable};
16use crate::query::queryable::QueryKeyValue;
17
18impl<E: Queryable> Query<E> {
19 #[must_use]
25 pub fn into_normal_representation(self) -> String {
26 self.to_string()
27 }
28}
29
30impl<E: Queryable> Display for Query<E> {
31 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32 if let Some(root) = &self.root {
33 root.fmt(f)
34 } else {
35 write!(f, "")
36 }
37 }
38}
39
40impl<E: Queryable> Display for Matcher<E> {
41 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42 match self {
43 Matcher::Or { lhs, rhs } => write!(f, r"({lhs} OR {rhs})"),
44 Matcher::And { lhs, rhs } => write!(f, r"({lhs} AND {rhs})"),
45 Matcher::Match { key_value } => {
46 let (key, value) = key_value.to_key_and_value();
47 write!(f, r#""{key}:{value}""#)
48 }
49 }
50 }
51}