diff --git a/src/codegen/rust.rs b/src/codegen/rust.rs index 23eb152..d52bf84 100644 --- a/src/codegen/rust.rs +++ b/src/codegen/rust.rs @@ -68,7 +68,7 @@ fn gen_enum(enum_: &schema::Enum, ns: &[String]) -> TokenStream { } }); if let Some(extends) = &enum_.extends { - let extends_typeref = gen_typeref_ref(&extends, ns); + let extends_typeref = gen_typeref_ref(extends, ns); let mut matches = TokenStream::new(); let extends_enum = enum_.extends_enum().unwrap(); for variant in extends_enum.borrow().all_variants.iter() { @@ -152,7 +152,7 @@ fn gen_validation_macros(field: &schema::Field) -> TokenStream { match field.format.as_deref() { Some("email") => rules.extend(quote! { email, }), Some("url") => rules.extend(quote! { url, }), - _ => {}, + _ => {} } match field.length { (Some(min), Some(max)) => rules.extend(quote! { length(min=#min, max=#max), }), @@ -201,7 +201,7 @@ fn gen_fieldset_field(field: &schema::FieldsetField, ns: &[String]) -> TokenStre fn gen_service(service: &schema::Service, ns: &[String]) -> TokenStream { let service_name = quote::format_ident!("{}", &service.name); - let methods = gen_service_methods(&service, ns); + let methods = gen_service_methods(service, ns); quote! { #[::async_trait::async_trait] pub trait #service_name { @@ -248,7 +248,7 @@ fn gen_provider(service: &schema::Service, ns: &[String]) -> TokenStream { format!("{}.{}", ns.join("."), &service.name) }; let provider_name = quote::format_ident!("{}Provider", service.name); - let matches = gen_provider_matches(&service, ns); + let matches = gen_provider_matches(service, ns); quote! { pub struct #provider_name(pub F); // NamedProvider impl @@ -332,7 +332,7 @@ fn gen_provider_matches(service: &schema::Service, ns: &[String]) -> TokenStream fn gen_consumer(service: &schema::Service, ns: &[String]) -> TokenStream { let consumer_name = quote::format_ident!("{}Consumer", service.name); - let consumer_methods = gen_consumer_methods(&service, ns); + let consumer_methods = gen_consumer_methods(service, ns); quote! { pub struct #consumer_name<'a>(pub &'a (dyn ::webwire::Consumer + ::std::marker::Sync + ::std::marker::Send)); impl<'a> #consumer_name<'a> { @@ -427,9 +427,7 @@ fn gen_typeref(type_: &schema::Type, ns: &[String]) -> TokenStream { } } // named - schema::Type::Ref(typeref) => { - gen_typeref_ref(typeref, ns) - } + schema::Type::Ref(typeref) => gen_typeref_ref(typeref, ns), schema::Type::Builtin(name) => { // FIXME unwrap... igh! let identifier: TokenStream = ::syn::parse_str(name).unwrap(); diff --git a/src/codegen/ts.rs b/src/codegen/ts.rs index e2847ee..8c678eb 100644 --- a/src/codegen/ts.rs +++ b/src/codegen/ts.rs @@ -54,7 +54,7 @@ pub fn gen(doc: &schema::Document) -> String { fn gen_namespace(ns: &schema::Namespace, gen: &mut Generator) { for type_ in ns.types.values() { gen.line(""); - gen_type(&*type_, gen); + gen_type(type_, gen); } for service in ns.services.values() { gen.line(""); @@ -72,9 +72,9 @@ fn gen_namespace(ns: &schema::Namespace, gen: &mut Generator) { fn gen_type(type_: &schema::UserDefinedType, gen: &mut Generator) { match type_ { - schema::UserDefinedType::Enum(enum_) => gen_enum(&*enum_.borrow(), gen), - schema::UserDefinedType::Struct(struct_) => gen_struct(&*struct_.borrow(), gen), - schema::UserDefinedType::Fieldset(fieldset) => gen_fieldset(&*fieldset.borrow(), gen), + schema::UserDefinedType::Enum(enum_) => gen_enum(&enum_.borrow(), gen), + schema::UserDefinedType::Struct(struct_) => gen_struct(&struct_.borrow(), gen), + schema::UserDefinedType::Fieldset(fieldset) => gen_fieldset(&fieldset.borrow(), gen), } } @@ -160,20 +160,20 @@ fn gen_fieldset(fieldset: &schema::Fieldset, gen: &mut Generator) { fn method_signature(method: &schema::Method) -> String { let input = match &method.input { - Some(t) => format!("input: {}", gen_typeref(&t)), + Some(t) => format!("input: {}", gen_typeref(t)), None => String::new(), }; let output = match &method.output { Some(t) => gen_typeref(t), None => "void".to_string(), }; - format!("{}({}): Promise<{}>", method.name, input, output) + format!("{}({}): webwire.Response<{}>", method.name, input, output) } fn gen_service(service: &schema::Service, gen: &mut Generator) { gen.begin(&format!("export interface {} {{", service.name)); for method in service.methods.iter() { - gen.line(&format!("{},", method_signature(&method))); + gen.line(&format!("{},", method_signature(method))); } gen.end("}"); } @@ -188,7 +188,7 @@ fn gen_consumer(ns: &schema::Namespace, service: &schema::Service, gen: &mut Gen gen.line("this._client = client"); gen.end("}"); for method in service.methods.iter() { - gen.begin(&format!("async {} {{", method_signature(&method))); + gen.begin(&format!("async {} {{", method_signature(method))); let fqsn = if ns.path.is_empty() { service.name.to_owned() } else { diff --git a/src/idl/common.rs b/src/idl/common.rs index 93b74ae..79aea04 100644 --- a/src/idl/common.rs +++ b/src/idl/common.rs @@ -56,8 +56,8 @@ pub fn parse_identifier_with_generics(input: Span) -> IResult( - output: IResult, T>, +pub(crate) fn assert_parse( + output: IResult, T>, expected_value: T, ) { assert!(output.is_ok(), "{:?}", output); diff --git a/src/idl/fieldset.rs b/src/idl/fieldset.rs index 13b98a5..f65729f 100644 --- a/src/idl/fieldset.rs +++ b/src/idl/fieldset.rs @@ -37,7 +37,7 @@ fn parse_field(input: Span) -> IResult { pair(preceded(ws, parse_identifier), preceded(ws, opt(char('?')))), |(name, optional)| Field { name, - optional: optional != None, + optional: optional.is_some(), }, )(input) } diff --git a/src/idl/struct.rs b/src/idl/struct.rs index d29d929..17db572 100644 --- a/src/idl/struct.rs +++ b/src/idl/struct.rs @@ -76,7 +76,7 @@ fn parse_field(input: Span) -> IResult { |((name, optional), (type_, options))| Field { name, position: input.into(), - optional: optional != None, + optional: optional.is_some(), type_, options: if let Some(options) = options { options @@ -431,7 +431,7 @@ fn test_parse_struct_with_fields() { #[test] fn test_parse_struct_with_fields_ws_variants() { - let contents = vec![ + let contents = [ "struct Person{name:String,age:Integer}", "struct Person {name:String,age:Integer}", "struct Person{ name:String,age:Integer}", @@ -481,7 +481,7 @@ fn test_parse_struct_with_generics() { #[test] fn test_parse_struct_with_generics_ws_variants() { - let contents = vec![ + let contents = [ "struct Wrapper{value:T}", "struct Wrapper {value:T}", "struct Wrapper< T>{value:T}", diff --git a/src/schema/enum.rs b/src/schema/enum.rs index cad7b77..8fb5539 100644 --- a/src/schema/enum.rs +++ b/src/schema/enum.rs @@ -41,13 +41,13 @@ impl Enum { value_type: ivariant .value_type .as_ref() - .map(|itype| Type::from_idl(itype, &ns, &builtin_types)), + .map(|itype| Type::from_idl(itype, ns, builtin_types)), }) .collect(); let extends = ienum .extends .as_ref() - .map(|itype| TypeRef::from_idl(itype, &ns, &builtin_types)); + .map(|itype| TypeRef::from_idl(itype, ns, builtin_types)); Self { fqtn: FQTN::new(&ienum.name, ns), generics: ienum.generics.clone(), @@ -91,12 +91,8 @@ impl Enum { Ok(variants) } pub fn extends_enum(&self) -> Option>> { - if let Some(extends) = &self.extends { - if let TypeRef::Enum(extends) = extends { - Some(extends.enum_.upgrade().unwrap()) - } else { - None - } + if let Some(TypeRef::Enum(extends)) = &self.extends { + Some(extends.enum_.upgrade().unwrap()) } else { None } @@ -104,6 +100,7 @@ impl Enum { } #[test] +#[allow(clippy::disallowed_names)] fn test_schema_enum_extends() { let idl = r" enum Foo { Foo } diff --git a/src/schema/fieldset.rs b/src/schema/fieldset.rs index 265d9ec..c456330 100644 --- a/src/schema/fieldset.rs +++ b/src/schema/fieldset.rs @@ -32,7 +32,7 @@ impl Fieldset { Self { fqtn: FQTN::new(&ifieldset.name, ns), generics: ifieldset.generics.clone(), - r#struct: TypeRef::from_idl(&ifieldset.r#struct, ns, &builtin_types), + r#struct: TypeRef::from_idl(&ifieldset.r#struct, ns, builtin_types), fields: ifieldset .fields .iter() diff --git a/src/schema/namespace.rs b/src/schema/namespace.rs index 5498047..9785668 100644 --- a/src/schema/namespace.rs +++ b/src/schema/namespace.rs @@ -30,7 +30,7 @@ impl Namespace { let mut ns = Self::default(); let mut type_map = TypeMap::new(); for ins in inss { - ns.idl_convert(ins, &mut type_map, &builtin_types)?; + ns.idl_convert(ins, &mut type_map, builtin_types)?; } ns.resolve(&type_map)?; Ok(ns) @@ -62,9 +62,9 @@ impl Namespace { idl::NamespacePart::Enum(ienum) => { self.add_type( UserDefinedType::Enum(Rc::new(RefCell::new(Enum::from_idl( - &ienum, + ienum, self, - &builtin_types, + builtin_types, )))), type_map, ); @@ -72,9 +72,9 @@ impl Namespace { idl::NamespacePart::Struct(istruct) => { self.add_type( UserDefinedType::Struct(Rc::new(RefCell::new(Struct::from_idl( - &istruct, + istruct, self, - &builtin_types, + builtin_types, )))), type_map, ); @@ -82,9 +82,9 @@ impl Namespace { idl::NamespacePart::Fieldset(ifieldset) => { self.add_type( UserDefinedType::Fieldset(Rc::new(RefCell::new(Fieldset::from_idl( - &ifieldset, + ifieldset, self, - &builtin_types, + builtin_types, )))), type_map, ); @@ -92,7 +92,7 @@ impl Namespace { idl::NamespacePart::Service(iservice) => { self.services.insert( iservice.name.clone(), - Service::from_idl(iservice, self, &builtin_types), + Service::from_idl(iservice, self, builtin_types), ); // This is done in the next step. Since services do not // define any types we can ignore the merging and just @@ -104,7 +104,7 @@ impl Namespace { ..Default::default() }; child_ns.path.push(ipart.name().to_owned()); - child_ns.idl_convert(&inamespace, type_map, &builtin_types)?; + child_ns.idl_convert(inamespace, type_map, builtin_types)?; self.namespaces.insert(inamespace.name.to_owned(), child_ns); } }; diff --git a/src/schema/service.rs b/src/schema/service.rs index e0dea2b..28c46bd 100644 --- a/src/schema/service.rs +++ b/src/schema/service.rs @@ -34,11 +34,11 @@ impl Service { input: imethod .input .as_ref() - .map(|x| Type::from_idl(x, ns, &builtin_types)), + .map(|x| Type::from_idl(x, ns, builtin_types)), output: imethod .output .as_ref() - .map(|x| Type::from_idl(x, ns, &builtin_types)), + .map(|x| Type::from_idl(x, ns, builtin_types)), }) .collect(), } diff --git a/src/schema/struct.rs b/src/schema/struct.rs index 7bf3235..674ec11 100644 --- a/src/schema/struct.rs +++ b/src/schema/struct.rs @@ -36,7 +36,7 @@ impl Struct { let fields = istruct .fields .iter() - .map(|ifield| Field::from_idl(ifield, ns, &builtin_types)) + .map(|ifield| Field::from_idl(ifield, ns, builtin_types)) .collect(); Self { fqtn: FQTN::new(&istruct.name, ns), @@ -71,7 +71,7 @@ impl Field { } Field { name: ifield.name.clone(), - type_: Type::from_idl(&ifield.type_, ns, &builtin_types), + type_: Type::from_idl(&ifield.type_, ns, builtin_types), optional: ifield.optional, // FIXME add options //options: ifield.options diff --git a/src/schema/type.rs b/src/schema/type.rs index 6782e97..7ef1667 100644 --- a/src/schema/type.rs +++ b/src/schema/type.rs @@ -103,15 +103,15 @@ impl Type { "Option" => Self::Option(Box::new(Type::from_idl( &ityperef.generics[0], ns, - &builtin_types, + builtin_types, ))), "Result" => Self::Result( - Box::new(Type::from_idl(&ityperef.generics[0], ns, &builtin_types)), - Box::new(Type::from_idl(&ityperef.generics[1], ns, &builtin_types)), + Box::new(Type::from_idl(&ityperef.generics[0], ns, builtin_types)), + Box::new(Type::from_idl(&ityperef.generics[1], ns, builtin_types)), ), name => match builtin_types.get(name) { Some(value) => Self::Builtin(value.to_owned()), - None => Self::Ref(TypeRef::from_idl(ityperef, ns, &builtin_types)), + None => Self::Ref(TypeRef::from_idl(ityperef, ns, builtin_types)), }, } } @@ -121,17 +121,17 @@ impl Type { builtin_types: &HashMap, ) -> Self { match itype { - idl::Type::Ref(ityperef) => Self::from_idl_ref(&ityperef, &ns, &builtin_types), + idl::Type::Ref(ityperef) => Self::from_idl_ref(ityperef, ns, builtin_types), idl::Type::Array(item_type) => Self::Array(Box::new(Array { - item_type: Self::from_idl(item_type, ns, &builtin_types), + item_type: Self::from_idl(item_type, ns, builtin_types), length: Range { start: None, end: None, }, // FIXME })), idl::Type::Map(key_type, value_type) => Self::Map(Box::new(Map { - key_type: Self::from_idl(key_type, ns, &builtin_types), - value_type: Self::from_idl(value_type, ns, &builtin_types), + key_type: Self::from_idl(key_type, ns, builtin_types), + value_type: Self::from_idl(value_type, ns, builtin_types), length: Range { start: None, end: None, @@ -198,7 +198,7 @@ impl TypeRef { generics: ityperef .generics .iter() - .map(|itype| Type::from_idl(itype, ns, &builtin_types)) + .map(|itype| Type::from_idl(itype, ns, builtin_types)) .collect(), } } @@ -216,15 +216,15 @@ impl TypeRef { } match ud_type { UserDefinedType::Enum(enum_) => TypeRef::Enum(EnumRef { - enum_: Rc::downgrade(&enum_), + enum_: Rc::downgrade(enum_), generics: generics.clone(), }), UserDefinedType::Struct(struct_) => TypeRef::Struct(StructRef { - struct_: Rc::downgrade(&struct_), + struct_: Rc::downgrade(struct_), generics: generics.clone(), }), UserDefinedType::Fieldset(fieldset) => TypeRef::Fieldset(FieldsetRef { - fieldset: Rc::downgrade(&fieldset), + fieldset: Rc::downgrade(fieldset), generics: generics.clone(), }), }