• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

davidcole1340 / ext-php-rs / 16186430696

10 Jul 2025 04:51AM UTC coverage: 22.342%. Remained the same
16186430696

Pull #488

github

web-flow
Merge b88d7b906 into 1de4bee12
Pull Request #488: feat: make Sapi work with ZTS builds

870 of 3894 relevant lines covered (22.34%)

3.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/crates/macros/src/constant.rs
1
use darling::FromAttributes;
2
use proc_macro2::TokenStream;
3
use quote::{format_ident, quote};
4
use syn::ItemConst;
5

6
use crate::helpers::get_docs;
7
use crate::parsing::{PhpRename, RenameRule};
8
use crate::prelude::*;
9

10
const INTERNAL_CONST_DOC_PREFIX: &str = "_internal_const_docs_";
11
const INTERNAL_CONST_NAME_PREFIX: &str = "_internal_const_name_";
12

13
#[derive(FromAttributes, Default, Debug)]
14
#[darling(default, attributes(php), forward_attrs(doc))]
15
pub(crate) struct PhpConstAttribute {
16
    #[darling(flatten)]
17
    pub(crate) rename: PhpRename,
18
    // TODO: Implement const Visibility
19
    // pub(crate) vis: Option<Visibility>,
20
    pub(crate) attrs: Vec<syn::Attribute>,
21
}
22

23
pub fn parser(mut item: ItemConst) -> Result<TokenStream> {
×
24
    let attr = PhpConstAttribute::from_attributes(&item.attrs)?;
×
25

26
    let name = attr
×
27
        .rename
×
28
        .rename(item.ident.to_string(), RenameRule::ScreamingSnake);
×
29
    let name_ident = format_ident!("{INTERNAL_CONST_NAME_PREFIX}{}", item.ident);
×
30

31
    let docs = get_docs(&attr.attrs)?;
×
32
    let docs_ident = format_ident!("{INTERNAL_CONST_DOC_PREFIX}{}", item.ident);
×
33
    item.attrs.retain(|attr| !attr.path().is_ident("php"));
×
34

35
    Ok(quote! {
×
36
        #item
37
        #[allow(non_upper_case_globals)]
38
        const #docs_ident: &[&str] = &[#(#docs),*];
39
        #[allow(non_upper_case_globals)]
40
        const #name_ident: &str = #name;
41
    })
42
}
43

44
pub fn wrap(input: &syn::Path) -> Result<TokenStream> {
×
45
    let Some(const_name) = input.get_ident().map(ToString::to_string) else {
×
46
        bail!(input => "Pass a PHP const into `wrap_constant!()`.");
×
47
    };
48
    let doc_const = format_ident!("{INTERNAL_CONST_DOC_PREFIX}{const_name}");
×
49
    let const_name = format_ident!("{INTERNAL_CONST_NAME_PREFIX}{const_name}");
×
50

51
    Ok(quote! {
×
52
        (#const_name, #input, #doc_const)
×
53
    })
54
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc