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>

source

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.
source

pub fn as_ref(self) -> Self

Sets the argument as a reference.

source

pub fn is_variadic(self) -> Self

Sets the argument as variadic.

source

pub fn allow_null(self) -> Self

Sets the argument as nullable.

source

pub fn default<T: Into<String>>(self, default: T) -> Self

Sets the default value for the argument.

source

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.

source

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.

source

pub fn variadic_vals<T>(&'a mut self) -> Vec<T>
where T: FromZvalMut<'a>,

Retrice all the variadic values for this Rust argument.

source

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.
source

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.

Trait Implementations§

source§

impl<'a> Debug for Arg<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<Arg<'_>> for _zend_expected_type

source§

fn from(arg: Arg<'_>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for Arg<'a>

§

impl<'a> !Send for Arg<'a>

§

impl<'a> !Sync for Arg<'a>

§

impl<'a> Unpin for Arg<'a>

§

impl<'a> !UnwindSafe for Arg<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.