ddoc/config/
menu_insert.rs

1use std::{
2    fmt,
3    str::FromStr,
4};
5
6/// A placeholder to insert the menu at this position in the nav bar
7///
8/// Rigth now there's no configuration but it could be extended in the future
9#[derive(Debug, Clone, Copy)]
10pub struct MenuInsert;
11
12impl FromStr for MenuInsert {
13    type Err = &'static str;
14    fn from_str(s: &str) -> Result<Self, Self::Err> {
15        if s != "menu" {
16            return Err("MenuInsert must be 'menu'");
17        }
18        Ok(Self)
19    }
20}
21impl fmt::Display for MenuInsert {
22    fn fmt(
23        &self,
24        f: &mut fmt::Formatter<'_>,
25    ) -> fmt::Result {
26        write!(f, "menu")
27    }
28}
29impl serde::Serialize for MenuInsert {
30    fn serialize<S: serde::Serializer>(
31        &self,
32        serializer: S,
33    ) -> Result<S::Ok, S::Error> {
34        serializer.serialize_str(&self.to_string())
35    }
36}
37impl<'de> serde::Deserialize<'de> for MenuInsert {
38    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
39        let s = String::deserialize(deserializer)?;
40        s.parse().map_err(serde::de::Error::custom)
41    }
42}