Skip to content

Commit d4ef116

Browse files
authored
Support marking methods as abstract (#154)
For classes that are registered with `#[php_impl]` this allows functions to be marked as abstract.
1 parent 5d1fda4 commit d4ef116

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

crates/macros/src/impl_.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pub enum ParsedAttribute {
8585
},
8686
Constructor,
8787
This,
88+
Abstract,
8889
}
8990

9091
#[derive(Default, Debug, FromMeta)]
@@ -212,6 +213,7 @@ pub fn parse_attribute(attr: &Attribute) -> Result<Option<ParsedAttribute>> {
212213
"public" => ParsedAttribute::Visibility(Visibility::Public),
213214
"protected" => ParsedAttribute::Visibility(Visibility::Protected),
214215
"private" => ParsedAttribute::Visibility(Visibility::Private),
216+
"abstract_method" => ParsedAttribute::Abstract,
215217
"rename" => {
216218
let ident = if let Meta::List(list) = meta {
217219
if let Some(NestedMeta::Lit(lit)) = list.nested.first() {

crates/macros/src/method.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub struct Method {
3838
pub optional: Option<String>,
3939
pub output: Option<(String, bool)>,
4040
pub _static: bool,
41+
pub _abstract: bool,
4142
pub visibility: Visibility,
4243
}
4344

@@ -81,6 +82,7 @@ pub fn parser(
8182
let mut visibility = Visibility::Public;
8283
let mut as_prop = None;
8384
let mut identifier = None;
85+
let mut is_abstract = false;
8486
let mut is_constructor = false;
8587
let docs = get_docs(&input.attrs);
8688

@@ -90,6 +92,7 @@ pub fn parser(
9092
ParsedAttribute::Default(list) => defaults = list,
9193
ParsedAttribute::Optional(name) => optional = Some(name),
9294
ParsedAttribute::Visibility(vis) => visibility = vis,
95+
ParsedAttribute::Abstract => is_abstract = true,
9396
ParsedAttribute::Rename(ident) => identifier = Some(ident),
9497
ParsedAttribute::Property { prop_name, ty } => {
9598
if as_prop.is_some() {
@@ -211,6 +214,7 @@ pub fn parser(
211214
optional,
212215
output: get_return_type(struct_ty, &input.sig.output)?,
213216
_static: matches!(method_type, MethodType::Static),
217+
_abstract: is_abstract,
214218
visibility,
215219
};
216220

@@ -447,6 +451,10 @@ impl Method {
447451
flags.push(quote! { Static });
448452
}
449453

454+
if self._abstract {
455+
flags.push(quote! { Abstract });
456+
}
457+
450458
flags
451459
.iter()
452460
.map(|flag| quote! { ::ext_php_rs::flags::MethodFlags::#flag })

0 commit comments

Comments
 (0)