Skip to main content

Args

Struct Args 

Source
pub struct Args<'a> { /* private fields */ }
Expand description

Typed list of arguments for a native function.

Generally the #[native] proc macro builds and consumes an Args automatically — call manually only in raw natives that receive (amx, args) directly.

Implementations§

Source§

impl<'a> Args<'a>

Source

pub fn new(amx: &'a Amx, params: *const i32) -> Args<'a>

Builds from the Amx and the args pointer received by the native.

§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 = Amx::new(amx, amx_exports);
    let mut args = Args::new(&amx, args);
    let Some(text) = args.next_arg::<AmxString>() else { return 0 };
    println!("RawNative: {}", &*text);
    1
}
Source

pub fn next_arg<T>(&mut self) -> Option<T>
where T: AmxCell<'a> + 'a,

Next argument in signature order. None at the end of the list.

Source

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

Argument at position offset (zero-indexed). None if out of bounds.

Source

pub fn reset(&mut self)

Resets the next_arg cursor back to the start of the list.

Source

pub fn count(&self) -> usize

How many arguments were received.

Reads from args[0] (total bytes) and divides by 4 (cell size). Negative or zero values return 0 — defense against dirty pointers.

Auto Trait Implementations§

§

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

§

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

§

impl<'a> Freeze for Args<'a>

§

impl<'a> RefUnwindSafe for Args<'a>

§

impl<'a> Unpin for Args<'a>

§

impl<'a> UnsafeUnpin for Args<'a>

§

impl<'a> UnwindSafe for Args<'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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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>,

Source§

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.