Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove infallible variants #265

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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