[][src]Struct samp::args::Args

pub struct Args<'a> { /* fields omitted */ }

A wrapper of a list of arguments of a native function.

Methods

impl<'a> Args<'a>[src]

pub fn new(amx: &'a Amx, args: *const i32) -> Args<'a>[src]

Creates a list from Amx and arguments.

Example

use samp_sdk::args::Args;
use samp_sdk::amx::Amx;
use samp_sdk::cell::AmxString;

// native: RawNative(const say_that[]);
extern "C" fn raw_native(amx: *mut AMX, args: *mut i32) -> i32 {
    // let amx_exports = ...;
    let amx = Amx::new(amx, amx_exports);
    let mut args = Args::new(&amx, args);

    let say_what = match args.next::<AmxString>() {
        Some(string) => string.to_string(),
        None => {
            println!("RawNative error: no argument");
            return 0;
        }
    };

    println!("RawNative: {}", say_what);

    return 1;
}

pub fn next<T>(&mut self) -> Option<T> where
    T: 'a + AmxCell<'a>, 
[src]

Return the next argument in the list (like an iterator).

When there is no arguments left returns None.

pub fn get<T>(&self, offset: usize) -> Option<T> where
    T: 'a + AmxCell<'a>, 
[src]

Get an argument by position, if there is no argument in given location, returns None.

Example

use samp_sdk::args::Args;
use samp_sdk::amx::Amx;
use samp_sdk::cell::Ref;

// native: NativeFn(player_id, &Float:health, &Float:armor);
extern "C" fn raw_native(amx: *mut AMX, args: *mut i32) -> i32 {
    // let amx_exports = ...;
    let amx = Amx::new(amx, amx_exports);
    let args = Args::new(&amx, args);

    // change only armor
    args.get::<Ref<f32>>(2)
        .map(|mut armor| *armor = 255.0);

    return 1;
}

pub fn reset(&mut self)[src]

Reset a read offset for next() method.

pub fn count(&self) -> usize[src]

Get count of arguments in the list.

Auto Trait Implementations

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

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

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.