Merge pull request #1001 from serde-rs/remotevis
Inherit the visibility of remote struct definition
This commit is contained in:
commit
ccec002bf3
@ -28,9 +28,10 @@ pub fn expand_derive_deserialize(input: &syn::DeriveInput) -> Result<Tokens, Str
|
|||||||
let body = Stmts(deserialize_body(&cont, ¶ms));
|
let body = Stmts(deserialize_body(&cont, ¶ms));
|
||||||
|
|
||||||
let impl_block = if let Some(remote) = cont.attrs.remote() {
|
let impl_block = if let Some(remote) = cont.attrs.remote() {
|
||||||
|
let vis = &input.vis;
|
||||||
quote! {
|
quote! {
|
||||||
impl #de_impl_generics #ident #ty_generics #where_clause {
|
impl #de_impl_generics #ident #ty_generics #where_clause {
|
||||||
fn deserialize<__D>(__deserializer: __D) -> _serde::export::Result<#remote #ty_generics, __D::Error>
|
#vis fn deserialize<__D>(__deserializer: __D) -> _serde::export::Result<#remote #ty_generics, __D::Error>
|
||||||
where __D: _serde::Deserializer<'de>
|
where __D: _serde::Deserializer<'de>
|
||||||
{
|
{
|
||||||
#body
|
#body
|
||||||
|
@ -29,9 +29,10 @@ pub fn expand_derive_serialize(input: &syn::DeriveInput) -> Result<Tokens, Strin
|
|||||||
let body = Stmts(serialize_body(&cont, ¶ms));
|
let body = Stmts(serialize_body(&cont, ¶ms));
|
||||||
|
|
||||||
let impl_block = if let Some(remote) = cont.attrs.remote() {
|
let impl_block = if let Some(remote) = cont.attrs.remote() {
|
||||||
|
let vis = &input.vis;
|
||||||
quote! {
|
quote! {
|
||||||
impl #impl_generics #ident #ty_generics #where_clause {
|
impl #impl_generics #ident #ty_generics #where_clause {
|
||||||
fn serialize<__S>(__self: &#remote #ty_generics, __serializer: __S) -> _serde::export::Result<__S::Ok, __S::Error>
|
#vis fn serialize<__S>(__self: &#remote #ty_generics, __serializer: __S) -> _serde::export::Result<__S::Ok, __S::Error>
|
||||||
where __S: _serde::Serializer
|
where __S: _serde::Serializer
|
||||||
{
|
{
|
||||||
#body
|
#body
|
||||||
|
@ -358,6 +358,21 @@ fn test_gen() {
|
|||||||
#[serde(borrow, with = "StrDef")]
|
#[serde(borrow, with = "StrDef")]
|
||||||
s: Str<'a>,
|
s: Str<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod vis {
|
||||||
|
pub struct S;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
#[serde(remote = "S")]
|
||||||
|
pub struct SDef;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This would not work if SDef::serialize / deserialize are private.
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
struct RemoteVisibility {
|
||||||
|
#[serde(with = "vis::SDef")]
|
||||||
|
s: vis::S,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
x
Reference in New Issue
Block a user