Skip to content

Argument default should be any expression, not just a literal value #433

@alekitto

Description

@alekitto

I'm trying to expose a function with a nullable argument, but I want to make the argument optional (default null).
I've tried to implement it like this:

#[php_function]
#[php(defaults(x = None))]
pub fn test_func(x: Option<String>) -> String {
    // ...
}

but this syntax is invalid.

defaults only accepts literal values (syn::Lit), but should probably accept any expression (syn::Expr maybe?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmacrosRelated to macros

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions