ekg_namespace/literal/
url_display.rs1use {
2 crate::literal::this::Literal,
3 std::fmt::{Display, Formatter},
4};
5
6pub struct LiteralUrlDisplay<'a> {
7 pub(crate) literal: &'a Literal,
8}
9
10impl<'a> Display for LiteralUrlDisplay<'a> {
11 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
12 if self.literal.data_type.is_string() {
13 write!(
14 f,
15 "{}",
16 serde_urlencoded::to_string(self.literal.as_str().unwrap_or(""))
17 .map_err(|_| std::fmt::Error)?
18 )
19 } else if self.literal.data_type.is_boolean() {
20 write!(
21 f,
22 "{:}",
23 self.literal.as_boolean().unwrap_or(false)
24 )
25 } else {
26 write!(f, "{:}", self.literal.to_string().as_str())
27 }
28 }
29}