Skip to content

Commit

Permalink
Fix mutable refs
Browse files Browse the repository at this point in the history
  • Loading branch information
joehoyle committed Jul 13, 2023
1 parent 614f5b4 commit 68059bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
8 changes: 1 addition & 7 deletions crates/macros/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,18 +343,12 @@ impl Arg {
}
Type::Reference(ref_) => {
// Returning references is invalid, so let's just create our arg

// Change any `&mut T` into `&T` and set the `as_ref` attribute on the Arg
// to marked it as a "passed by ref" PHP argument.
let mut ref_ = ref_.clone();
let is_mutable_ref = ref_.mutability.is_some();
ref_.mutability = None;
Some(Arg::new(
name,
ref_.to_token_stream().to_string(),
false,
default,
is_mutable_ref,
ref_.mutability.is_some(),
))
}
_ => None,
Expand Down
14 changes: 14 additions & 0 deletions guide/src/types/bool.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,17 @@ pub fn test_bool(input: bool) -> String {
var_dump(test_bool(true)); // string(4) "Yes!"
var_dump(test_bool(false)); // string(3) "No!"
```

## Rust example, taking by reference

```rust,no_run
# #![cfg_attr(windows, feature(abi_vectorcall))]
# extern crate ext_php_rs;
# use ext_php_rs::prelude::*;
# use ext_php_rs::types;
#[php_function]
pub fn test_bool(input: &mut types::Zval) {
input.reference_mut().unwrap().set_bool(false);
}
# fn main() {}
```

0 comments on commit 68059bd

Please sign in to comment.