anybox/lib.rs
1//! one API for the most popular passthrough boxes. you connect, and anybox figures out which box it is, the
2//! firmware, and what it can do, then you call the same methods without having to worry about which box is plugged in
3//!
4//! ```no_run
5//! use anybox::{Button, Event, Key};
6//!
7//! fn main() -> anybox::Result<()> {
8//! let device = anybox::connect()?;
9//! device.move_by(100, 0)?;
10//! device.click(Button::Left)?;
11//! device.tap_key(Key::A)?;
12//!
13//! for event in device.events() {
14//! if let Event::Button { button, pressed: true, .. } = event {
15//! println!("{button:?} down");
16//! }
17//! }
18//! Ok(())
19//! }
20//! ```
21//!
22//! if a box can't do something, the call fails with [`Error::Unsupported`] and says why, nothing is faked or
23//! changed behind your back. [`Device::snapshot`] tells you up front what the box in front of you can do right
24//! now, which also depends on what's plugged into it. things only one box has stay reachable through that box's
25//! own API, like `device.medius()` on a Medius
26//!
27//! the README has the full picture, which box does what, the differences between them, and how to add your own
28//! fallback for something a box can't do: <https://github.com/etherealrl/anybox>
29
30// with a box family left out, the shared code only the others use has nothing calling it
31#![cfg_attr(
32 not(all(
33 feature = "medius",
34 feature = "makcu",
35 feature = "ferrum",
36 feature = "ysc8k"
37 )),
38 allow(dead_code)
39)]
40
41mod backend;
42mod capability;
43mod click;
44mod connect;
45mod device;
46mod error;
47mod event;
48mod family;
49mod key;
50mod transport;
51
52pub use capability::{
53 Action, Axis, Button, Capabilities, Capability, Direction, Execution, Family, FerrumApi,
54 Firmware, Info, Quirk, Snapshot, StableId, UsbIds,
55};
56pub use click::{Click, ClickTiming, Timing};
57pub use connect::{Connect, Found, Scanned, candidates, connect, scan};
58pub use device::Device;
59pub use error::{Error, Result};
60pub use event::{
61 BoxTime, Clock, Closed, DropSource, Event, EventKinds, Events, RecvTimeoutError, Stamp,
62 TryRecvError, monotonic_ns,
63};
64#[cfg(feature = "mock")]
65pub use family::medius::mock::MockPoller;
66pub use key::{Key, MediaKey};
67#[cfg(feature = "medius")]
68pub use medius;
69
70// the readme's examples get compiled with the tests, so they can't drift from the API
71#[cfg(doctest)]
72#[doc = include_str!("../README.md")]
73struct ReadmeExamples;