gdvariants

Rust std library collections wrapper that implements the godot-rust variant traits for convenience when using godot-rust.

Traits implemented on top of the standard library implementation:

Types

Usage

Add this to your Cargo.toml:

~~~toml gdvariants = "*" ~~~

Read the godot-rust book for information on how to setup a Godot project that uses Rust.

Property

~~~rust use gdnative::api::; use gdnative::prelude::;

use gdvariants::collections::HashMap;

[derive(NativeClass, Default)]

[inherit(Node)]

pub struct ExampleHashMapProperty { #[property] players: HashMap, } ~~~

Networking

~~~rust use gdnative::api::; use gdnative::prelude::;

use gdvariants::collections::HashMap;

...

fn send_data(&mut self, owner: &Node) { let mut data: HashMap = HashMap::new(); data.insert(1, 0);

for player in self.players.keys() {
    owner.rpc_id(*player, "data", &[data.to_variant()]);
}

} ~~~

~~~rust use gdnative::api::; use gdnative::prelude::;

use gdvariants::collections::HashMap;

...

fn receive_data(&mut self, owner: &Node, data: HashMap) { let mut data: HashMap = HashMap::new(); data.insert(1, 0);

for player in self.players.keys() {
    owner.rpc_id(*player, "data", &[data.to_variant()]);
}

} ~~~