Crate p5_sys

Crate p5_sys 

Source
Expand description

p5-sys crate(library) is bindings to p5.js for Rust/Wasm.

*** Nightly rustc is required ***

Currently,almost all global function works. The instance methods and properties don’t work. For example, vector.add() will not work. You are advised to use rust types for such tasks. Also functions that take arrays and modify them will not work.

The documentation is taken from p5.js reference and are not ported to rust yet.

§Example

use p5::*;
 
pub struct State {
    x: f64,
}
 
#[wasm_bindgen]
pub fn setup() -> State {
    createCanvas(400., 400., RENDERER::Webgl);
    background(123., 234., 124.);
    return State {
        x: 10.,
    }
}
 
#[wasm_bindgen]
pub fn draw(state: &mut State) {
    state.x += 1;
    rect(state.x, 40., 100., 120.);
}

We don’t have mutable global variable in Rust, so we have to use state. setup creates the state. draw and other event handlers recieve a mutable reference to it, means that they can change it.

Re-exports§

pub use global::*;
pub use types::*;
pub use constants::*;

Modules§

constants
global
types

Structs§

Closure
A handle to both a closure in Rust as well as JS closure which will invoke the Rust closure.
JsError
Convenience type for use on exported fn() -> Result<T, JsError> functions, where you wish to throw a JavaScript Error object.
JsValue
Representation of an object owned by JS.

Traits§

JsCast
A trait for checked and unchecked casting between JS types.
UnwrapThrowExt
An extension trait for Option<T> and Result<T, E> for unwrapping the T value, or throwing a JS error if it is not available.

Attribute Macros§

__wasm_bindgen_class_marker
wasm_bindgen
A list of all the attributes can be found here: https://rustwasm.github.io/docs/wasm-bindgen/reference/attributes/index.html