2022-06-18 21:56:31 -07:00
|
|
|
use super::*;
|
2019-11-21 06:23:32 -08:00
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
pub(crate) trait Keyed<'key> {
|
|
|
|
fn key(&self) -> &'key str;
|
|
|
|
}
|
2019-11-21 06:23:32 -08:00
|
|
|
|
|
|
|
impl<'key, T: Keyed<'key>> Keyed<'key> for Rc<T> {
|
|
|
|
fn key(&self) -> &'key str {
|
|
|
|
self.as_ref().key()
|
|
|
|
}
|
|
|
|
}
|
2021-11-17 00:07:48 -08:00
|
|
|
|
|
|
|
pub(crate) fn serialize<'src, S, K>(keyed: &K, serializer: S) -> Result<S::Ok, S::Error>
|
|
|
|
where
|
|
|
|
S: Serializer,
|
|
|
|
K: Keyed<'src>,
|
|
|
|
{
|
2022-01-30 12:16:10 -08:00
|
|
|
serializer.serialize_str(keyed.key())
|
2021-11-17 00:07:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn serialize_option<'src, S, K>(
|
|
|
|
recipe: &Option<K>,
|
|
|
|
serializer: S,
|
|
|
|
) -> Result<S::Ok, S::Error>
|
|
|
|
where
|
|
|
|
S: Serializer,
|
|
|
|
K: Keyed<'src>,
|
|
|
|
{
|
|
|
|
match recipe {
|
|
|
|
None => serializer.serialize_none(),
|
|
|
|
Some(keyed) => serialize(keyed, serializer),
|
|
|
|
}
|
|
|
|
}
|