Smallest viable rust-samp plugin. One native, no state, no lifecycle overrides.
#[derive(SampPlugin, Default)]— empty trait impl, no manualimpl SampPlugin.initialize_plugin!(type: Hello, natives: [...])— short form that usesDefault::default()as the constructor.&AmxStringargument — the macro injects the borrow automatically.AmxStringthroughDeref<Target = str>—&**namereads the decoded string without an extra allocation.UnsizedBuffer::write_str— output string written in one call.
native Hello_Greet(const name[], greeting[] = "", size = sizeof(greeting));Behavior:
- Empty
name→ writesHello, Anonymous!. namestarting withAdmin→ writes[ADMIN] Welcome, <name>!.- Otherwise → writes
Hello, <name>! (<len> letters).
public OnGameModeInit()
{
new buf[64];
Hello_Greet("World", buf);
print(buf); // "Hello, World! (5 letters)"
return 1;
}cargo build --release --target i686-unknown-linux-gnu -p helloOutput: target/i686-unknown-linux-gnu/release/libhello.so.
See src/lib.rs.