1#![forbid(unsafe_code)]
4#![warn(missing_docs)]
5#![cfg_attr(feature = "unstable-doc-cfg", feature(doc_auto_cfg))]
6
7use std::{fmt::Display, marker::PhantomData, str::FromStr};
8
9use serde::de::{Error, Visitor};
10
11pub mod certificate;
12pub mod id;
13pub mod property;
14pub mod proto;
15pub mod service;
16
17#[cfg(feature = "access_token")]
18pub mod access_token;
19
20#[cfg(feature = "document")]
21pub mod document;
22
23#[cfg(feature = "mtls_server")]
24pub mod mtls_server;
25
26pub mod policy;
27
28#[derive(Default)]
29struct FromStrVisitor<T> {
30 expecting: &'static str,
31 phantom: PhantomData<T>,
32}
33
34impl<T> FromStrVisitor<T> {
35 pub fn new(expecting: &'static str) -> Self {
36 Self {
37 expecting,
38 phantom: PhantomData,
39 }
40 }
41}
42
43impl<T: FromStr> Visitor<'_> for FromStrVisitor<T>
44where
45 T::Err: Display,
46{
47 type Value = T;
48
49 fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
50 write!(f, "{}", self.expecting)
51 }
52
53 fn visit_str<E: Error>(self, str: &str) -> Result<Self::Value, E> {
54 T::from_str(str).map_err(|msg| E::custom(msg))
55 }
56}