2019-11-21 06:23:32 -08:00
|
|
|
use crate::common::*;
|
|
|
|
|
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>,
|
|
|
|
{
|
|
|
|
serializer.serialize_str(&keyed.key())
|
|
|
|
}
|
|
|
|
|
|
|
|
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),
|
|
|
|
}
|
|
|
|
}
|