Move extern fn signature fields to struct
This will allow reusing the Signature struct for the type of function
pointers.
diff --git a/syntax/impls.rs b/syntax/impls.rs
index 741431a..dfaab55 100644
--- a/syntax/impls.rs
+++ b/syntax/impls.rs
@@ -1,6 +1,15 @@
-use crate::syntax::{Ref, Ty1, Type};
+use crate::syntax::{ExternFn, Ref, Signature, Ty1, Type};
use std::hash::{Hash, Hasher};
use std::mem;
+use std::ops::Deref;
+
+impl Deref for ExternFn {
+ type Target = Signature;
+
+ fn deref(&self) -> &Self::Target {
+ &self.sig
+ }
+}
impl Hash for Type {
fn hash<H: Hasher>(&self, state: &mut H) {
diff --git a/syntax/mod.rs b/syntax/mod.rs
index 79a4a7b..f2e1c1c 100644
--- a/syntax/mod.rs
+++ b/syntax/mod.rs
@@ -46,13 +46,17 @@
pub struct ExternFn {
pub lang: Lang,
pub doc: Doc,
- pub fn_token: Token![fn],
pub ident: Ident,
+ pub sig: Signature,
+ pub semi_token: Token![;],
+}
+
+pub struct Signature {
+ pub fn_token: Token![fn],
pub receiver: Option<Receiver>,
pub args: Vec<Var>,
pub ret: Option<Type>,
pub throws: bool,
- pub semi_token: Token![;],
}
pub struct Var {
diff --git a/syntax/parse.rs b/syntax/parse.rs
index 00ea15c..e07ee25 100644
--- a/syntax/parse.rs
+++ b/syntax/parse.rs
@@ -1,5 +1,6 @@
use crate::syntax::{
- attrs, error, Api, Atom, Doc, ExternFn, ExternType, Lang, Receiver, Ref, Struct, Ty1, Type, Var,
+ attrs, error, Api, Atom, Doc, ExternFn, ExternType, Lang, Receiver, Ref, Signature, Struct,
+ Ty1, Type, Var,
};
use proc_macro2::Ident;
use quote::quote;
@@ -207,12 +208,14 @@
Ok(ExternFn {
lang,
doc,
- fn_token,
ident,
- receiver,
- args,
- ret,
- throws,
+ sig: Signature {
+ fn_token,
+ receiver,
+ args,
+ ret,
+ throws,
+ },
semi_token,
})
}