Skip to main content

wackasm_opencomputers/
lib.rs

1//! Typed Rust bindings to OpenComputers, for programs running on the
2//! WebAssembly (wackasm) architecture.
3//!
4//! Build an ordinary WASI program (`--target wasm32-wasip1`) and use
5//! components directly:
6//!
7//! ```no_run
8//! use wackasm_opencomputers::prelude::*;
9//!
10//! let gpu = Gpu::first().expect("no GPU");
11//! let (w, h) = gpu.get_resolution()?;
12//! gpu.fill(1, 1, w, h, " ")?;
13//! gpu.set(1, 1, "hello from Rust", None)?;
14//!
15//! // Wait for a key.
16//! let key = signal::pull_filtered(None, |s| matches!(s, Signal::KeyDown { .. }));
17//! # Ok::<(), wackasm_opencomputers::Error>(())
18//! ```
19//!
20//! * [`components`]: a generated struct per component type (`Gpu`,
21//!   `Filesystem`, `Robot`, `Modem`, `Redstone`, ...), with a method for every
22//!   callback and OpenComputers' own docs.
23//! * [`component`]: finding components, and untyped calls ([`Proxy`]).
24//! * [`signal`]: typed events.
25//! * [`computer`]: this computer's address, uptime, memory and power.
26//! * [`process`]: running other programs, like `std::process`.
27//! * [`draw`]: a framebuffer with text, half-block pixels, braille and
28//!   shapes, sent to the GPU with as few calls as possible.
29//! * [`internet`]: HTTP requests and TCP connections through an internet card.
30//! * `task` (with the `async` feature): an async executor, so programs can
31//!   wait on several component calls, timers and signals at once. Every
32//!   component method then has an `_async` twin.
33//! * [`Side`], [`Color`], [`keys`]: the numeric codes components use.
34//!
35//! Files are simplest through `std::fs`, which the architecture maps onto a
36//! disk. The `Filesystem` wrapper is there for other disks.
37//!
38//! Numbers cross as [`Number`]: an integer or a float, as OpenComputers sent
39//! it, so integers stay exact.
40
41pub mod component;
42pub mod components;
43pub mod computer;
44pub mod draw;
45mod error;
46pub mod internet;
47pub mod process;
48pub mod signal;
49mod sys;
50#[cfg(feature = "async")]
51pub mod task;
52mod types;
53mod value;
54
55pub use component::{Address, Component, MethodInfo, Proxy};
56pub use error::{Error, Result};
57pub use signal::Signal;
58pub use types::{Color, Side, keys};
59pub use value::{Handle, Number, OcString, Value};
60
61/// Everything a typical program needs: `use wackasm_opencomputers::prelude::*;`
62pub mod prelude {
63    pub use crate::{
64        Address, Color, Component, Error, Handle, Number, OcString, Proxy, Result, Side, Signal, Value,
65        components::*, computer, keys,
66        internet,
67        process::{self, Command},
68        signal,
69    };
70}