Skip to content

Commit

Permalink
Merge pull request #265 from davidcole1340/rm_infallible
Browse files Browse the repository at this point in the history
Remove infallible variants
  • Loading branch information
danog authored Oct 10, 2023
2 parents eff7b01 + 4152ffc commit 7d484a0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
6 changes: 2 additions & 4 deletions guide/src/types/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ PHP functions and methods are represented by the `Function` struct.
You can use the `try_from_function` and `try_from_method` methods to obtain a Function struct corresponding to the passed function or static method name.
It's heavily recommended you reuse returned `Function` objects, to avoid the overhead of looking up the function/method name.

You may also use the infallible `from_function` and `from_method` variants, for example when working with native PHP functions/classes that are guaranteed to be always available.

```rust,no_run
# #![cfg_attr(windows, feature(abi_vectorcall))]
# extern crate ext_php_rs;
Expand All @@ -16,13 +14,13 @@ use ext_php_rs::zend::Function;
#[php_function]
pub fn test_function() -> () {
let var_dump = Function::from_function("var_dump");
let var_dump = Function::try_from_function("var_dump").unwrap();
let _ = var_dump.try_call(vec![&"abc"]);
}
#[php_function]
pub fn test_method() -> () {
let f = Function::from_method("ClassName", "staticMethod");
let f = Function::try_from_method("ClassName", "staticMethod").unwrap();
let _ = f.try_call(vec![&"abc"]);
}
Expand Down
14 changes: 0 additions & 14 deletions src/zend/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,6 @@ impl Function {
}
}

pub fn from_function(name: &str) -> Self {
match Self::try_from_function(name) {
Some(v) => v,
None => panic!("Expected function `{}` to exist!", name),
}
}

pub fn from_method(class: &str, name: &str) -> Self {
match Self::try_from_method(class, name) {
Some(v) => v,
None => panic!("Expected method `{}::{}` to exist!", class, name),
}
}

/// Attempts to call the callable with a list of arguments to pass to the
/// function.
///
Expand Down

0 comments on commit 7d484a0

Please sign in to comment.