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//! * [`pattern_provider`]: autocrafting patterns for Applied Energistics 2
31//! that the program fulfils (with AE2 installed).
32//! * `task` (with the `async` feature): an async executor, so programs can
33//! wait on several component calls, timers and signals at once. Every
34//! component method then has an `_async` twin.
35//! * [`Side`], [`Color`], [`keys`]: the numeric codes components use.
36//!
37//! Files are simplest through `std::fs`, which the architecture maps onto a
38//! disk. The `Filesystem` wrapper is there for other disks.
39//!
40//! Numbers cross as [`Number`]: an integer or a float, as OpenComputers sent
41//! it, so integers stay exact.
42
43pub mod component;
44pub mod components;
45pub mod computer;
46pub mod draw;
47mod error;
48pub mod internet;
49pub mod pattern_provider;
50pub mod process;
51pub mod signal;
52mod sys;
53#[cfg(feature = "async")]
54pub mod task;
55mod types;
56mod value;
57
58pub use component::{Address, Component, MethodInfo, Proxy};
59pub use error::{Error, Result};
60pub use signal::Signal;
61pub use types::{Color, Side, keys};
62pub use value::{Handle, Number, OcString, Value};
63
64/// Everything a typical program needs: `use wackasm_opencomputers::prelude::*;`
65pub mod prelude {
66 pub use crate::{
67 Address, Color, Component, Error, Handle, Number, OcString, Proxy, Result, Side, Signal, Value,
68 components::*, computer, keys,
69 internet,
70 pattern_provider::{self, PatternProvider},
71 process::{self, Command},
72 signal,
73 };
74}