Fix bug which made code generation dependend on argument ordering

This commit is contained in:
konstin 2018-07-06 12:56:40 +02:00
parent 1201587353
commit 562d417517
3 changed files with 11 additions and 10 deletions

View file

@ -5,14 +5,12 @@
extern crate pyo3;
extern crate rayon;
use pyo3::prelude::*;
use pyo3::py::{class, methods, modinit};
use rayon::prelude::*;
use std::fs::File;
use std::io::prelude::*;
use pyo3::prelude::*;
use rayon::prelude::*;
use pyo3::py::{class, methods, modinit};
#[class(dict)]
struct WordCounter {
path: String,

View file

@ -16,8 +16,11 @@ pub fn build_py_class(class: &mut syn::ItemStruct, attr: &Vec<syn::Expr>) -> Tok
if let syn::Fields::Named(ref mut fields) = class.fields {
for field in fields.named.iter_mut() {
if is_python_token(field) {
token = field.ident.clone();
break;
if token.is_none() {
token = field.ident.clone();
} else {
panic!("You can only have one PyToken per class");
}
} else {
let field_descs = parse_descriptors(field);
if !field_descs.is_empty() {
@ -48,8 +51,8 @@ fn parse_descriptors(item: &mut syn::Field) -> Vec<FnType> {
"set" => {
descs.push(FnType::Setter(None));
}
_ => {
panic!("Only getter and setter supported");
x => {
panic!(r#"Only "get" and "set" supported are, not "{}""#, x);
}
}
}

View file

@ -52,11 +52,11 @@ fn class_with_properties() {
#[class]
struct GetterSetter {
token: PyToken,
#[prop(get, set)]
num: i32,
#[prop(get, set)]
text: String,
token: PyToken,
}
#[methods]