Skip to main content

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 one box family left out, the shared code only the other one uses has nothing calling it
31#![cfg_attr(not(all(feature = "medius", feature = "makcu")), allow(dead_code))]
32
33mod backend;
34mod capability;
35mod click;
36mod connect;
37mod device;
38mod error;
39mod event;
40mod family;
41mod key;
42mod transport;
43
44pub use capability::{
45    Action, Axis, Button, Capabilities, Capability, Direction, Execution, Family, Firmware, Info,
46    Quirk, Snapshot, StableId,
47};
48pub use click::{Click, ClickTiming, Timing};
49pub use connect::{Connect, Found, connect, find};
50pub use device::Device;
51pub use error::{Error, Result};
52pub use event::{
53    BoxTime, Clock, Closed, DropSource, Event, EventKinds, Events, RecvTimeoutError, Stamp,
54    TryRecvError,
55};
56#[cfg(feature = "mock")]
57pub use family::medius::mock::MockPoller;
58pub use key::{Key, MediaKey};
59#[cfg(feature = "medius")]
60pub use medius;
61
62// the readme's examples get compiled with the tests, so they can't drift from the API
63#[cfg(doctest)]
64#[doc = include_str!("../README.md")]
65struct ReadmeExamples;