Remove some old-syn clutter
This commit is contained in:
parent
bc412ede8f
commit
1201587353
|
@ -207,7 +207,7 @@ fn function_wrapper_ident(name: &syn::Ident) -> syn::Ident {
|
||||||
/// Generates python wrapper over a function that allows adding it to a python module as a python
|
/// Generates python wrapper over a function that allows adding it to a python module as a python
|
||||||
/// function
|
/// function
|
||||||
pub fn add_fn_to_module(
|
pub fn add_fn_to_module(
|
||||||
func: &mut syn::ItemFn,
|
func: &syn::ItemFn,
|
||||||
python_name: &syn::Ident,
|
python_name: &syn::Ident,
|
||||||
pyfn_attrs: Vec<args::Argument>,
|
pyfn_attrs: Vec<args::Argument>,
|
||||||
) -> TokenStream {
|
) -> TokenStream {
|
||||||
|
|
|
@ -1,22 +1,19 @@
|
||||||
// Copyright (c) 2017-present PyO3 Project and Contributors
|
// Copyright (c) 2017-present PyO3 Project and Contributors
|
||||||
|
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use syn;
|
|
||||||
|
|
||||||
use method::{FnArg, FnSpec, FnType};
|
use method::{FnArg, FnSpec, FnType};
|
||||||
use proc_macro2::{Span, TokenStream};
|
use proc_macro2::{Span, TokenStream};
|
||||||
use py_method::{impl_py_getter_def, impl_py_setter_def, impl_wrap_getter, impl_wrap_setter};
|
use py_method::{impl_py_getter_def, impl_py_setter_def, impl_wrap_getter, impl_wrap_setter};
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use syn;
|
||||||
use utils;
|
use utils;
|
||||||
|
|
||||||
pub fn build_py_class(ast: &mut syn::DeriveInput, attr: &Vec<syn::Expr>) -> TokenStream {
|
pub fn build_py_class(class: &mut syn::ItemStruct, attr: &Vec<syn::Expr>) -> TokenStream {
|
||||||
let (params, flags, base) = parse_attribute(attr);
|
let (params, flags, base) = parse_attribute(attr);
|
||||||
let doc = utils::get_doc(&ast.attrs, true);
|
let doc = utils::get_doc(&class.attrs, true);
|
||||||
let mut token: Option<syn::Ident> = None;
|
let mut token: Option<syn::Ident> = None;
|
||||||
let mut descriptors = Vec::new();
|
let mut descriptors = Vec::new();
|
||||||
|
|
||||||
if let syn::Data::Struct(ref mut struc) = ast.data {
|
if let syn::Fields::Named(ref mut fields) = class.fields {
|
||||||
if let syn::Fields::Named(ref mut fields) = struc.fields {
|
|
||||||
for field in fields.named.iter_mut() {
|
for field in fields.named.iter_mut() {
|
||||||
if is_python_token(field) {
|
if is_python_token(field) {
|
||||||
token = field.ident.clone();
|
token = field.ident.clone();
|
||||||
|
@ -31,15 +28,8 @@ pub fn build_py_class(ast: &mut syn::DeriveInput, attr: &Vec<syn::Expr>) -> Toke
|
||||||
} else {
|
} else {
|
||||||
panic!("#[class] can only be used with C-style structs")
|
panic!("#[class] can only be used with C-style structs")
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
panic!("#[class] can only be used with structs")
|
|
||||||
}
|
|
||||||
|
|
||||||
let tokens = impl_class(&ast.ident, &base, token, doc, params, flags, descriptors);
|
impl_class(&class.ident, &base, token, doc, params, flags, descriptors)
|
||||||
|
|
||||||
quote! {
|
|
||||||
#tokens
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_descriptors(item: &mut syn::Field) -> Vec<FnType> {
|
fn parse_descriptors(item: &mut syn::Field) -> Vec<FnType> {
|
||||||
|
|
|
@ -88,7 +88,7 @@ pub fn class(
|
||||||
input: proc_macro::TokenStream,
|
input: proc_macro::TokenStream,
|
||||||
) -> proc_macro::TokenStream {
|
) -> proc_macro::TokenStream {
|
||||||
// Parse the token stream into a syntax tree
|
// Parse the token stream into a syntax tree
|
||||||
let mut ast: syn::DeriveInput = syn::parse(input).expect("#[class] must be used on a `struct`");
|
let mut ast: syn::ItemStruct = syn::parse(input).expect("#[class] must be used on a `struct`");
|
||||||
|
|
||||||
// Parse the macro arguments into a list of expressions
|
// Parse the macro arguments into a list of expressions
|
||||||
let args: Vec<syn::Expr> = {
|
let args: Vec<syn::Expr> = {
|
||||||
|
|
Loading…
Reference in New Issue