From 4152ffca06bee05a610629d3ce74d29bfecb607c Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 10 Oct 2023 16:07:39 +0200 Subject: [PATCH] Remove infallible variants --- guide/src/types/functions.md | 6 ++---- src/zend/function.rs | 14 -------------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/guide/src/types/functions.md b/guide/src/types/functions.md index c8d7b0315..475a27b79 100644 --- a/guide/src/types/functions.md +++ b/guide/src/types/functions.md @@ -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; @@ -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"]); } diff --git a/src/zend/function.rs b/src/zend/function.rs index 97c9ec0d6..a1ef8663c 100644 --- a/src/zend/function.rs +++ b/src/zend/function.rs @@ -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. ///