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.
Examples found in repository?
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
pub fn build() {
if CLOSURE_META.has_ce() {
panic!("Closure has already been built.");
}
let ce = ClassBuilder::new("RustClosure")
.method(
FunctionBuilder::new("__invoke", Self::invoke)
.not_required()
.arg(Arg::new("args", DataType::Mixed).is_variadic())
.returns(DataType::Mixed, false, true)
.build()
.expect("Failed to build `RustClosure` PHP class."),
MethodFlags::Public,
)
.object_override::<Self>()
.build()
.expect("Failed to build `RustClosure` PHP class.");
CLOSURE_META.set_ce(ce);
}
sourcepub fn is_variadic(self) -> Self
pub fn is_variadic(self) -> Self
Sets the argument as variadic.
Examples found in repository?
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
pub fn build() {
if CLOSURE_META.has_ce() {
panic!("Closure has already been built.");
}
let ce = ClassBuilder::new("RustClosure")
.method(
FunctionBuilder::new("__invoke", Self::invoke)
.not_required()
.arg(Arg::new("args", DataType::Mixed).is_variadic())
.returns(DataType::Mixed, false, true)
.build()
.expect("Failed to build `RustClosure` PHP class."),
MethodFlags::Public,
)
.object_override::<Self>()
.build()
.expect("Failed to build `RustClosure` PHP class.");
CLOSURE_META.set_ce(ce);
}
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 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.