Struct ext_php_rs::args::Arg
source · pub struct Arg<'a> { /* private fields */ }
Expand description
Represents an argument to a function.
Implementations§
source§impl<'a> Arg<'a>
impl<'a> Arg<'a>
sourcepub fn new<T: Into<String>>(name: T, _type: DataType) -> Self
pub fn new<T: Into<String>>(name: T, _type: DataType) -> Self
Creates a new argument.
§Parameters
name
- The name of the parameter._type
- The type of the parameter.
sourcepub fn is_variadic(self) -> Self
pub fn is_variadic(self) -> Self
Sets the argument as variadic.
sourcepub fn allow_null(self) -> Self
pub fn allow_null(self) -> Self
Sets the argument as nullable.
sourcepub fn default<T: Into<String>>(self, default: T) -> Self
pub fn default<T: Into<String>>(self, default: T) -> Self
Sets the default value for the argument.
sourcepub fn consume<T>(self) -> Result<T, Self>where
for<'b> T: FromZvalMut<'b>,
pub fn consume<T>(self) -> Result<T, Self>where
for<'b> T: FromZvalMut<'b>,
Attempts to consume the argument, converting the inner type into T
.
Upon success, the result is returned in a Result
.
If the conversion fails (or the argument contains no value), the
argument is returned in an Err
variant.
As this function consumes, it cannot return a reference to the underlying zval.
sourcepub fn val<T>(&'a mut self) -> Option<T>where
T: FromZvalMut<'a>,
pub fn val<T>(&'a mut self) -> Option<T>where
T: FromZvalMut<'a>,
Attempts to retrieve the value of the argument. This will be None until the ArgParser is used to parse the arguments.
sourcepub fn variadic_vals<T>(&'a mut self) -> Vec<T>where
T: FromZvalMut<'a>,
pub fn variadic_vals<T>(&'a mut self) -> Vec<T>where
T: FromZvalMut<'a>,
Retrice all the variadic values for this Rust argument.
sourcepub fn zval(&mut self) -> Option<&mut &'a mut Zval>
pub fn zval(&mut self) -> Option<&mut &'a mut Zval>
Attempts to return a reference to the arguments internal Zval.
§Returns
Some(&Zval)
- The internal zval.None
- The argument was empty.
sourcepub fn try_call(&self, params: Vec<&dyn IntoZvalDyn>) -> Result<Zval>
pub fn try_call(&self, params: Vec<&dyn IntoZvalDyn>) -> Result<Zval>
Attempts to call the argument as a callable with a list of arguments to pass to the function. Note that a thrown exception inside the callable is not detectable, therefore you should check if the return value is valid rather than unwrapping. Returns a result containing the return value of the function, or an error.
You should not call this function directly, rather through the
call_user_func
macro.
§Parameters
params
- A list of parameters to call the function with.