Skip to main content

CellConvert

Trait CellConvert 

Source
pub trait CellConvert: Sized {
    // Required methods
    fn from_cell(raw: i32) -> Self;
    fn into_cell(self) -> i32;
}
Expand description

Conversion between Rust and an AMX cell (i32) without needing &Amx.

Difference vs AmxCell: this trait operates on standalone values, ideal for bulk operations over Buffer (each element is an independent cell).

TraitWhen to useNeeds &Amx?
AmxCellArgument of a #[native]Yes (for complex types)
CellConvertElement of a BufferNo

Rarely needs to be imported/implemented directly — Buffer::get_as and Buffer::set_as already consume this trait.

§Example

fn scale_floats(buf: &mut Buffer, factor: f32) {
    for i in 0..buf.len() {
        if let Some(v) = buf.get_as::<f32>(i) {
            buf.set_as(i, v * factor);
        }
    }
}

Required Methods§

Source

fn from_cell(raw: i32) -> Self

Decodes a raw i32 into the Rust type.

Source

fn into_cell(self) -> i32

Encodes the value as a raw cell.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl CellConvert for bool

Source§

impl CellConvert for f32

Source§

impl CellConvert for i8

Source§

impl CellConvert for i16

Source§

impl CellConvert for i32

Source§

impl CellConvert for isize

Source§

impl CellConvert for u8

Source§

impl CellConvert for u16

Source§

impl CellConvert for u32

Source§

impl CellConvert for usize

Implementors§