ruma_macros/serde/
serialize_as_ref_str.rs
1use proc_macro2::{Ident, TokenStream};
2use quote::quote;
3
4use crate::util::import_ruma_common;
5
6pub fn expand_serialize_as_ref_str(ident: &Ident) -> syn::Result<TokenStream> {
7 let ruma_common = import_ruma_common();
8
9 Ok(quote! {
10 #[automatically_derived]
11 #[allow(deprecated)]
12 impl #ruma_common::exports::serde::ser::Serialize for #ident {
13 fn serialize<S>(&self, serializer: S) -> ::std::result::Result<S::Ok, S::Error>
14 where
15 S: #ruma_common::exports::serde::ser::Serializer,
16 {
17 ::std::convert::AsRef::<::std::primitive::str>::as_ref(self).serialize(serializer)
18 }
19 }
20 })
21}