serde_path/
util.rs

1use std::{ops::Deref, sync::Arc};
2
3#[derive(Clone, Debug, PartialEq, Eq, Hash)]
4pub struct PercentDecodedStr(Arc<str>);
5
6impl PercentDecodedStr {
7    pub(crate) fn new<S>(s: S) -> Option<Self>
8    where
9        S: AsRef<str>,
10    {
11        percent_encoding::percent_decode(s.as_ref().as_bytes())
12            .decode_utf8()
13            .ok()
14            .map(|decoded| Self(decoded.as_ref().into()))
15    }
16
17    pub(crate) fn as_str(&self) -> &str {
18        &self.0
19    }
20
21    pub(crate) fn into_inner(self) -> Arc<str> {
22        self.0
23    }
24}
25
26impl Deref for PercentDecodedStr {
27    type Target = str;
28
29    #[inline]
30    fn deref(&self) -> &Self::Target {
31        self.as_str()
32    }
33}