Crate yareio_sys[][src]

Expand description

Rust bindings for Yare.io bots

crates.io docs.rs

This crate uses wasm-bindgen to expose the objects available to Yare.io bots to Rust. It’s meant to be used with yareio-rust-template, which contains custom build scripts necessary to make wasm-bindgen work with Yare.

This crate is documented with Rustdoc.

This crate is compatible with TypeScript, but you will need to use the TypeScript types from yareio-typescript-typings.

See also yare-rust for an alternative to this crate.

Usage notes

The methods and structs this crate provides map pretty directly to what’s available in JS. This means they won’t always be idiomatic Rust. For example, Deref-based inheritance is ued extensively; this is an antipattern for idiomatic Rust but it’s also the most performant way to represent JS inheritance hierarchies, and it’s what wasm-bindgen uses. The idiomatic alternative would be to use trait objects, but this would add additional dynamic dispatch on top of what JS already does, making it slower.

Passing values between WebAssembly and JS is slow, especially when those values aren’t numbers. Generally, any method in this crate that returns a value involves such a transfer of data (functions that return static references don’t). So be careful, and only retrieve the information you need.

For the reasons mentioned in the previous paragraphs, you may want to create you own structs and data structures to store the information you need.

Shape features

To access shape-specific methods like merge(), jump(), and explode(), you’ll need to enable the crate feature corresponding to the shape you play with in your Cargo.toml. The available shape features are circles, squares, and triangles.

Prelude

This crate has a prelude module that re-exports the most useful items. You can bulk-import them all with

use yareio_sys::prelude::*;

RenderService bindings

This crate optionally provides bindings for yare-code-sync’s RenderService, under the render_service module. You will need to enable the crate’s RenderService feature to use these bindings.

Modules

base

Provides access to player bases.

console

Provides access to console.log().

graphics

Provides access to the built-in graphics methods.

memory
outpost

Provides access to outposts.

players

Bindings relating to player IDs.

prelude

The most useful items to import.

render_service

Provides bindings for RenderService from yare-code-sync. To use this module, you will need to enable the crate’s RenderService feature.

spirit

Provides access to spirits.

star

Provides access to stars.

Macros

log

Calls console.log() with the given comma-separated list of Into<JsValue> arguments.

Structs

ArrayTypedIter

Iterator returned by EnumerateByID’s methods.

Destructible

Any Entity that can potentially be destroyed: can be a Spirit or Base.

DestructibleID

The ID of a Destructible.

Entity

Any object potentially on the game board: can be a Spirit, Base, Outpost, or Star.

EntityID

The ID of an Entity.

LivingDestructible

Any Destructible that has not yet been destroyed.

LivingDestructibleID

The ID of a LivingDestructible.

LivingEntity

Any object on the game board (not destroyed): can be a Spirit, Base, Outpost, or Star.

LivingEntityID

The ID of a LivingEntity.

OutpostSight

The sight of an outpost.

Position

A position on the game board. Ordered pair of f64.

Sight

The sight of a spirit or base.

Structure

A structure, i.e. anything with a structure_type: can be a [Base], [Outpost], or [Star].

StructureID

The ID of a Structure.

Enums

Shape

The possible values of a spirit or base’s shape property.

StructureType

The possible structure_types.

Statics

tick

Traits

EnumerateByID

This trait is implemented for the global objects that give mappings of IDs to entities: spirits, bases, outposts, and stars. It allows iterating over entities by their ID.

GetByID

This trait is implemented for the global objects that give mappings of IDs to entities: spirits, bases, outposts, and stars. It allows fetching entities by their ID.

TryGetByID

This trait is implemented for the global objects that give mappings of IDs to entities: spirits, bases, outposts, and stars. It allows faillibly fetching entities by their ID.