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.
As this function consumes, it cannot return a reference to the underlying zval.
§Errors
If the conversion fails (or the argument contains no value), the
argument is returned in an Err variant.
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.
§Errors
Error::Callable- The argument is not callable.