syn-serde 0.3.2

Library to serialize and deserialize Syn syntax trees.
Documentation
// SPDX-License-Identifier: Apache-2.0 OR MIT

use alloc::boxed::Box;

use super::*;
pub use crate::{
    ast_enum::Type,
    ast_struct::{
        Abi, BareFnArg, BareVariadic, TypeArray, TypeBareFn, TypeGroup, TypeImplTrait, TypeMacro,
        TypeParen, TypePath, TypePtr, TypeReference, TypeSlice, TypeTraitObject, TypeTuple,
    },
};

ast_struct! {
    /// An adapter for [`enum@syn::ReturnType`].
    #[derive(Default)]
    #[serde(transparent)]
    pub struct ReturnType {
        ty: Option<Box<Type>>,
    }
}

mod convert {
    use super::*;

    // ReturnType
    syn_trait_impl!(syn::ReturnType);
    impl From<&syn::ReturnType> for ReturnType {
        fn from(other: &syn::ReturnType) -> Self {
            use syn::ReturnType;
            match other {
                ReturnType::Default => Self { ty: None },
                ReturnType::Type(_, x) => Self { ty: Some(x.map_into()) },
            }
        }
    }
    impl From<&ReturnType> for syn::ReturnType {
        fn from(other: &ReturnType) -> Self {
            use syn::ReturnType;
            match &other.ty {
                None => ReturnType::Default,
                Some(x) => ReturnType::Type(default(), x.map_into()),
            }
        }
    }
}