ruma_macros/serde/
serialize_as_ref_str.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use proc_macro2::{Ident, TokenStream};
use quote::quote;

use crate::util::import_ruma_common;

pub fn expand_serialize_as_ref_str(ident: &Ident) -> syn::Result<TokenStream> {
    let ruma_common = import_ruma_common();

    Ok(quote! {
        #[automatically_derived]
        #[allow(deprecated)]
        impl #ruma_common::exports::serde::ser::Serialize for #ident {
            fn serialize<S>(&self, serializer: S) -> ::std::result::Result<S::Ok, S::Error>
            where
                S: #ruma_common::exports::serde::ser::Serializer,
            {
                ::std::convert::AsRef::<::std::primitive::str>::as_ref(self).serialize(serializer)
            }
        }
    })
}